Error: 'object' is not an exported object from 'namespace:package'? - r

I am using a package called {butteR} and a function called butteR::closest_distance_rtree() to match coordinates with their closest known settlement. The code looks like this:
# install.packages("devtools")
# devtools::install_github("zackarno/butteR")
matched_coordinates <- butteR::closest_distance_rtree(coordinates, master_settlement_list)
Should be simple enough, but I keep getting the following error:
Error: 'knn.RTree' is not an exported object from 'namespace:rtree'
I've re-installed both {butteR} and {rtree}, checked the namespace for {rtree}, re-started R and cleared the environment, and checked for typos. Any ideas would be appreciated!

Related

Why does wrapper function result in error

I'm trying to include a function from the Bioconductor package "simpIntLists" in my own package. "import(simpIntLists)" is added to the Namespace file.
However, the function results in an error
do_xy <- function(organism, IDType){
network <- simpIntLists::findInteractionList(organism, IDType)
}
do_xy("human", "EntrezId")
#Error message
data set ‘HumanBioGRIDInteractionEntrezId’ not foundError in get("HumanBioGRIDInteractionEntrezId") :
object 'HumanBioGRIDInteractionEntrezId' not found
# results in the same error (outside of the function)
simpIntLists::findInteractionList(organism, IDType)
It works fine when simpIntLists is attached
# works
library(simpIntLists)
network <- simpIntLists::findInteractionList(organism, IDType)
I saw the code here (https://bioconductor.org/packages/release/data/experiment/html/simpIntLists.html).
This code does not seem to take into account the situation where the package is used without installation.
For your information, the relevant part to this error is around the line 52.
else if (organism == 'human'){
if (idType == 'EntrezId'){
data(HumanBioGRIDInteractionEntrezId);
interactionList <- get("HumanBioGRIDInteractionEntrezId");
}
It tries to fetch the data to the namespace but it fails to do so if the package is not imported via library yet. This only generates a warning. The error then occurs when it tries to use the data because it does not exist in the namespace.
A workaround is that you import the data in your code explicitly. Then you can use the function as below. Note that the warning remains because of the embedded package code. If the warning is annoying, use suppressWarnings.
data(HumanBioGRIDInteractionEntrezId, package="simpIntLists")
simpIntLists::findInteractionList("human", "EntrezId")

PreprocessCore package

I'm quite new to R and I got an assignment that includes a sourcecode.
Part of the source code includes the following line:
library(preprocessCore)
Then I have in my source code a definition of the following function:
quantile.normalize.raw.gtex <- function(edata.mat)
{
norm_edata = normalize.quantiles(as.matrix(edata.mat))
rownames(norm_edata) = rownames(edata.mat)
colnames(norm_edata) = colnames(edata.mat)
return(norm_edata)
}
Finally, I have an object being initialized to the output of this function, after sending a predefined parameter:
tissue.edata.qn = quantile.normalize.raw.gtex(tissue.edata)
From what I understand, the library function is supposed to include the function normalize.quantiles, which is called in the function that is defined in my source code.
However, when I run the line library(preprocessCore) I get the following error:
Error in library(preprocessCore) :
there is no package called ‘preprocessCore’
I also tried to run the rest of the code and got the error:
Error in normalize.quantiles(as.matrix(edata.mat)) :
could not find function "normalize.quantiles"
I looked for the preprocessCore online and eventually I tried to write install.packages("preprocessCore"), but I got a warning message that this package is only available in version 3.6.0 of R, even though I checked and this is the version that I have.
If somebody has any idea what the problem is, I will appreciate your help.
Thanks in advance
The preprocessCore package is available in Bioconductor. So, to install it, you need the following lines:
source("http://bioconductor.org/biocLite.R")
biocLite("preprocessCore")
After that, you can load the package using library(preprocessCore)
Hope it helps.

Error : could not find function "ImportMethodFrom"

I tried to run the code in Chapter 7 Data mining with R learning with case study book but I got an error in following line:
rankWorkflows(svm, maxs = TRUE)
The error was:
Error in as.character.default(X[[i]], ...) : no method for coercing
this S4 class to a vector
Then I searched on the internet and found following solution:
importMethodsFrom(GenomicRanges, as.data.frame)
and again again I got a new error:
Error: could not find function "importMethodFrom"
I searched a lot but I got nothing :(
You can try using library(sos) to find the packages where your function is located.
library(sos)
findFn("replaceherewithyourfunction")
Based on the answer of #Bea, there does not seem to be a importMethodsFrom anywhere in R. My guess is you found the call in a NAMESPACE file. Those files have different syntax than normal R scripts.
If you want to load a specific function from an R package (rather than all functions from a package), you can use libraryname::functionname instad of functionname in your code. In your case, replace as.data.frame with GenomicRanges::as.data.frame
If this does not work (for example because you don't have as.data.frame anywhere in your code), you can also load the whole GenomicRanges library with library(GenomicRanges)

R package 'biomod2' cannot find file when executing plot function

I am attempting to use the plot() function in the biomod2 package, following a vignette here (http://finzi.psych.upenn.edu/usr/share/doc/library/biomod2/doc/Simple_species_modelling.pdf). Below is the error I am getting:
getwd()
# [1] "/home/gjanzen/Documents/Hufford/Drought/Data/Layers"
plot(myBiomodData)
Error in getExportedValue(pkg, name) : cannot open file
'~/R/x86_64-pc-linux-gnu-library/3.3/viridisLite/data/Rdata.rdb': No
such file or directory In addition: Warning message: In
getExportedValue(pkg, name) : restarting interrupted promise
evaluation
I have confirmed that the Rdata.rdb exists, in the following directory:
f <- file.choose()
f
# [1] "/home/gjanzen/R/x86_64-pc-linux-gnu-library/3.3/viridisLite/data/Rdata.rdb"
So, to me, it looks like the plot() function is looking in the wrong place. How can I change where this function looks for Rdata.rdb? Can I alter the path somehow? Or would changing my working directory fix this?
PS - This is my first post on Stack Overflow, so please forgive any mistakes in etiquette, and/or feel free to point them out to me so that I do not repeat them.
I think that the first thing to try is to reinstall the package viridisLite that seems to be the one that is causing troubles.
install.packages('viridisLite', dep = TRUE)
If this not solves the issue you should try to open a new plotting device threw x11() to check if the issue is not coming from the R (resp. RStudio) plotting device itself.

Error: 'MonetDBLite' is not an exported object from 'namespace:MonetDBLite'

Working through a download script for CPS data found here. Using the script verbatim, per recent update, except for the Java modification that I added for my environment (below) to fix a previous error in loadnamespace. While I am familiar with the basics of R, this is my first foray into MonetDBLite.
# configure Java
if (Sys.getenv("JAVA_HOME")!="")
Sys.setenv(JAVA_HOME="")
library(rJava)
Now I am getting the following error, which generally comes after 380,000 of the 400,000 cps asec lines are processed.
Warning message:
In readLines(url) :
incomplete final line found on 'http://thedataweb.rm.census.gov/pub/cps/march/asec2015early_pubuse.dd.txt'
Error in dbConnect(MonetDBLite::MonetDBLite(), dbfolder) :
error in evaluating the argument 'drv' in selecting a method for function 'dbConnect': Error: 'MonetDBLite' is not an exported object from 'namespace:MonetDBLite'
MonetDBLite has just been updated on CRAN, please reinstall.

Resources