BiodiversityR::accumcomp.long function not found - r

I am trying to use the function accumcomp.long in the Biodiversity.R package in order to adjust my species accumulation curves in ggplot.
However, calling the function accumcomp.long gives me an error, suggesting that this function perhaps does no longer exists.
accum.long1 <- accumcomp.long(Accum.1, ci=NA, label.freq=5)
Error in accumcomp.long(Accum.1, ci = NA, label.freq = 5) :
could not find function "accumcomp.long"
The function BiodiversityR::accumcomp.long
returns
Error: 'accumcomp.long' is not an exported object from 'namespace:BiodiversityR'
I am not certain whether this is an issue with the package, the way the package is loaded into my R space, or perhaps unrelated to the package simply the format of my data.
My community and environment files are of dataframe class. I have tried loading them as .csv files as well as .rda files, but the error remains.
??accumcomp.long
renders "No results found".
I am using R version 3.5.3 (2019-03-11)
Any suggestions as to what else I could try?
Thanks in advance!

I re-installed the package BiodiversityR and included force = T (as per this thread https://community.rstudio.com/t/could-not-find-function-error-even-though-fun-is-in-namespace-and-has-an-rd-file/91243). I then reloaded the package. I am not sure what force = T does, but the accumcomp.long function now works.

Related

How can I install and use (mice) function in R?

I want to use mice function to handle the missing data that I have in (data). I installed the package and I called the library. However, when I am trying to apply the function to my data it gives me error as below:
(Error in mice(data[, 5:9], m = 3, seed = 123) :
could not find function "mice")
I have a normal data frame that includes NAs
install.packages('mice')
library(mice)
library(VIM)
md.pattern(data)
md.pairs(data)
My_New_Data <- mice(data[,5:9], m=3, seed=123)
I am expecting the function to solve the problem and replace the NAs with reasonable values. It did not work at all!
Edit (incorporating comment suggestion)
In the comments the running mice::mice(data[, 5:9], m = 3, seed = 123). I ran this and the following error was returned.
Error in get(Info[i, 1], envir = env):
lazy-load database 'C:/Users/MUSTAFA KAMAL/Documents/R/win-library/3.5/broom/R/broom.rdb' is corrupt
In addition:
Warning message: In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1
In order to incorporate an answer to this question, I will rewrite my comment which resolved the problem, in the form of a short answer.
From the comments executing mice::mice(data[, 5:9], m = 3, seed = 123) resulted in an error message, showing the directory ~/Documents/R/win-library/**3.5**/broom/R/broom.rdb being corrupt.
From the corrupted directory path, one can see that OP was running R-3.5.x, while the newest version is R-3.6.x. Some packages updated since the most recent R-update has experienced similar problems, as such a first step towards solving these types of issues is updating R. The installr contains the function updateR which can help smooth over such updates, while also updating any outdated packages.
As a side note, an update sometimes fails to update the actual packages or results in other packages being corrupted, as such if an error persists one solution is to simply delete and re-install the package (or the entire ~/Documents/R/win-library/3.z/ directory). In the question from OP the corrupt package is the broom package, as such one could re-install this package by running
remove.packages("broom")
install.packages("broom")
which should resolve any leftover issues. Note however multiple packages might be corrupt, and likely only one will be shown every time the function is executed. In such cases a full package clear will do the trick, but requires re-installing all packages. For this one can export all installed packages prior to removing them all, by noting that a full list of installed packages is contained in installed.packages(), which can then be exported to a file with for example write.table or write.csv.

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.

Where did the forecast.Holtwinters go in R 3.4.3?

I'm using R Studio based on R 3.4.3. However, when I tried to call the forecast.HoltWinters function, R told me that "could not find function "forecast.HoltWinters"". Inspect the installed package (v8.2) told me that it's true, there is no forecast.HoltWinters. But the manual in https://cran.r-project.org/web/packages/forecast/ clearly stated that forecast.HoltWinters is still available.
I have also tried stats::HoldWinters, but it's working wrong. The code run fine on another computer, but it couldn't run at all on mine. Is there any solution?
Here is the code. Book2.csv has enough data to last more than 3 periods.
dltt <- read.csv("book2.csv", header = TRUE)
dltt.ts <- ts(dltt$Total, frequency=12, start=c(2014,4))
dltt.ts.hw <- HoltWinters(dltt.ts)
library(forecast)
dltt.ts.hw.fc <- forecast.HoltWinters(dltt.ts.hw) //Error as soon as I run this line
Fit a HoltWinters model using the HoltWinters function and then use forecast. Its all in the help for HoltWinters and forecast, namely "The function invokes particular _methods_ which depend on the class of the first argument". I'll copy the guts of it here:
m <- HoltWinters(co2)
forecast(m)
Note this will call the non-exported forecast.HoltWinters function, which you should never call directly using triple-colon notation as some may suggest.

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)

How to correct for "Error in nullmodel(comm, method) : could not find function "list2env" in the vegan package

I'm busy exploring the package vegan for R, using it to calculate nestedness of community matrices and null models. I'm particularly interested in using the permat functions as well as Oecosimu.
However, when running my program I obtained the following errors:
Error in nullmodel(comm, method) : could not find function "list2env"
Error in nullmodel(m, ALGO) : could not find function "list2env"
I then even ran an example (given below) of how to use these functions given by the R help function, and even these examples gave the same error. Am I suppose to import something else in order to use these functions or how do I go about fixing this?
Examples:
m <- matrix(c(
1,3,2,0,3,1,
0,2,1,0,2,1,
0,0,1,2,0,3,
0,0,0,1,4,3
), 4, 6, byrow=TRUE)
x1 <- permatswap(m, "quasiswap")
summary(x1)
x2 <- permatfull(m)
summary(x2)
x3 <- permatfull(m, "none", mtype="prab")
x3$orig
summary(x3)
x4 <- permatfull(m, strata=c(1,1,2,2))
summary(x4)
Technically, this is a bug in the development version of Vegan on R-Forge. We were failing to declare a dependency on R versions >= 2.12 in DESCRIPTION. I have checked in the relevant change to the source tree to fix this but it will take a day or so before the tarball and binaries are rebuilt by R-Forge.
That said, you should probably update your R to something more recent. Or use the versions of those functions provided in Vegan 2.0-x on CRAN.
list2env is part of R base, which means it comes with the distribution, not in an add-on package. So if you don't have it you're probably either running an old version of R or have a broken installation. The example worked fine for me, with R 2.12.1 and vegan 2.1-0.
Your code works for me without an error message
The most probable cause of your error is your using old versions of R, vegan or permute
The R news for changes says
CHANGES IN R VERSION 2.12.0: NEW FEATURES:
o New list2env() utility function as an inverse of
as.list(<environment>) and for fast multi-assign() to existing
environment. as.environment() is now generic and uses list2env()
as list method.
CHANGES IN R VERSION 2.12.1: BUG FIXES:
o When list2env() created an environment it was missing a PROTECT
call and so was vulnerable to garbage collection.
CHANGES IN R VERSION 2.13.0: NEW FEATURES:
o list2env(envir = NULL) defaults to hashing (with a suitably sized
environment) for lists of more than 100 elements.
So update your version of R and the packages and try again.

Resources