Cannot load forecast or RcppArmadillo packages from Script - r

When I run the commands library(forecast) and library(RcppArmadillo), there is no error. However, when I try to run these commands from a script, my script is unable to execute.
There are a few nuances to this case. Firstly, I only encounter this error on machines with R version > 2.14. I successfully ran this script on R 2.13.0, and encountered the error on machines with R version 2.14.1 and 2.14.2.
Additionally, the command find.package("forecast"), and similarly find.package("RcppArmadillo") does not return an error from inside the script, meaning that the script can locate the packages but cannot load them.
I have successfully ran a script replacing library(forecast) with the following 6 other packages: Rcpp, tseries,fracdiff,qcc,quadprog, zoo, and parallel.
Does anyone know why I cannot load these two packages from a script even though I can load them in the R console, and why this error occurs only for R versions > 2.14? My initial thought was that it might be related to the fact that these packages depend on R>=2.14.
Thank You Very Much.

We found that the issue was that RcppArmadillo depends on the Rlapack.dll file, which the script was not able to locate when loading the library. The solution was to copy the Rlapack.dll file to the library/RcppArmadillo/libs/i386 subfolder. After making this change, we were able to successfully execute our script.
We have two questions about this issue.
1) Why, when executing via R console, were we able to locate the Rlapack.dll file, when, during script execution, we were unable to find the dependent file?
2) Why did this issue occur only in R > 2.14? Was this a result of an update to either the RcppArmadillo or forecast packages?

Related

R: stats package functions such as rnorm() and runif() do not work

After updating R, I found that some functions like rnorm() and runif() were not working. Functions don't work not only in my code, but even the simplest examples like rnorm(100, mean = 5, sd = 2). R writes that can't find the function "rnorm". Everything else works. What does this mean? These are standard functions of the Stats package, I can't install or reinstall it. What could be the problem?
When loading, R gives a message about the problem:
"Error: package or namespace load failed for ‘stats’ in inDL(x, as.logical(local), as.logical(now), ...):
can't load shared object 'C:/Program Files/R/R-4.0.2/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module was not found."
I use the latest version of Windows 10, my current version of R is 4.0.2. I installed R 4.0.3, but the problem remained
I had the same issue as you, but deleting temporary RStudio files did not fix it for me. I found that my PATH variable was incorrect, and when I updated it my base packages were working again. The Sys.getenv("PATH") function will tell you where your current PATH variable is set to, which should be wherever you have installed R. For whatever reason, my PATH was set to C:\\rtools40\\usr\\bin but, for me, should be C:\Program Files\R\R-4.0.3\bin\x64. I updated the PATH with Sys.setenv(PATH="C:/Program Files/R/R-4.0.3/bin/x64") and that fixed it for me.
It seems that the problem was not with R, but with RStudio. I installed a fresh version of R, but the problem remained. This was already suspicious. The error that was displayed in the R Studio console indicated a problem with a specific library, but it was still not R itself, but with RStudio. I decided to check what would happen if I ran the same command in pure R. The command worked normally, so everything was fine with R itself and its libraries. I deleted the temporary files of RStudio and after that everything started running normally in it.

R package not found, but present in correct library

I have a problem with the R package "gridExtra". Everything is ok, when I go into R and load it, but when I execute a python script, which among others also loads this package, everything stops. I don't understand it, since I checked the library and the right library is selected.
It's a little complicated, because the script is from someone else. It can be accessed from here: https://github.com/guigolab/ggsashimi/blob/master/sashimi-plot.py. The package is loaded at row 430. Loading the previous packages was no problem, after installing them into the custom library. During the python script, a custom R script is generated and executed. Within this R script, the package is loaded usign the function library(gridExtra).
The error message is:
Error in library(gridExtra) : there is no package called ‘gridExtra’
Execution halted
I checked, if the generated R script really accesses the right library and it does, so there is no problem with the library selection.

how to read a SAS data (.sas7bat) in R [duplicate]

I am trying to embed RInside to my application on win7 64-bit system but when I initialize an RInside:
Rin = new RInside(argc, argv);
the following message appears:
Error in loadNamespace(name) : there is no package called 'Rcpp'
This error only occurs with Windows.
I think you get that issue when your .libPaths() differ--in other words run the .libPaths() function to see the paths stored by R for its use. Then check where RInside is installed, and make sure Rcpp is installed there too. It is a setup issue.
In other words, it should work if you have Rcpp and RInside installed where the basic R libraries are. Otherwise you have to tell the (embedded) R session about the other location (and before it starts).
There are more Windows users on the list, so you could try asking on rcpp-devel.
First get your default library locations by command ".Library" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step1.
Now you are ready to install packages which have dependencies on Rcpp.
Dirk is right in this case, BUT if the .libPaths() does not work, then please also check if you have the latest packages.
I am posting this as an ancillary answer backup which I ran into with the shiny package backend switch of their code needing Rcpp!
In this case of getting the "no package" error message, I fixed it by:
Selecting devtools package and then using this line below. (if you don't have devtools then get it with install.packages("devtools")
devtools::install_github("rstudio/shiny")
The development version of the package handled this better, and added the package as a dependency.
Mods - I realize this is an answer to an old question, but I might help others not wasting an hour like I just did.
You might find it easy if the answers are for both R studio users and non R studio users.
R Studio users
First get your default library locations by command ".Library" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step 1, you will find another folder named library, paste the unzip folder in it.
Non R studio Users
First get your default library locations by command ".libPath" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step 1, you will find another folder named library, paste the unzip folder in it.
I was also getting this error while trying to run the 'ggplot' function from the ggplot2 package. After trying the suggestions posted here and elsewhere (checking file paths, restarting R, clearing out my environment, etc.) and encountering several other cryptic error messages, it turned out that I needed to download the latest version of base R for Windows (v3.4.1) and update my version of R-Studio to the latest version also (v1.0.153).
After doing this my 'ggplot' function was working again and I was able to render my figure from R Studio without any further issues.
I was also getting this message when trying to use ggplot. I first updating both my R for Windows to 3.4.3. Then updating R studio to version 1.1.423; then, updating all of the packages and being sure to access the R version 3.4.3 from R studio, I still got the message. None of these things fixed the error. I was ready to give up until I noticed that I was calling library(ggplot) and had ggplot::ggplot in my code. THIS WAS THE PROBLEM. I changed it to library(ggplot2) and the instance to ggplot2::ggplot(...). THIS FIXEd the problems.
I was facing a similar issue, and I simply installed the said package. It's working perfectly for me.

Why does building an R package stop my code from working?

It seams that upon installing my custom R package code stops to work? Why?
In detail, I have a tiny R package goEnrichment (click to see the Github repo). The R package includes just just two functions and some binary data.
Also there are two test R-scripts that I run after installing the R package with R CMD INSTALL goEnrichment. One test script fails while the other works.
The only difference between the two scripts is that in the working version I require the necessary libraries and source the functions file manually, while in the other failing script I require my goEnrichment library directly.
Note, that both scripts are started directly from their directory goEnrichment/exec.
Start the working test with cd goEnrichment/exec && Rscript testGoEnrichment_works.R. Excerpt:
# This is the WORKING version
require(GOstats)
require(GSEABase)
require(RMySQL)
source( "../R/goEnrichment.R" )
Start the failing test script with cd goEnrichment/exec && Rscript testGoEnrichment_fail.R. Excerpt:
# This version FAILS
require(goEnrichment)
The error I get is somewhat uninformative to me:
'dimnames' applied to non-array.
The built R package fails on two platforms, that is on Debian Wheezy 64 with R 3.0.2 and on Mac OS X Yosemite with R 3.1.1.
I really have no clue why this happens. I checked for file format and unexpected characters using Vim. The cause does not seem to be the DESCRIPTION file either, because all libraries, goEnrichment depends on, are imported.
Does any one have a clue what causes this very weird error? Help will be much appreciated.
After much testing I found the source of the problem.
For some reason when requiring my package with
require(goEnrichment)
the generic function
summary.GOHyperGResult
is not loaded, as it should be. The method however is available when the packages, goEnrichment depends upon, are required manually. As to why this is, I had no time to investigate. I believe the here reported error is related to this bug.
Thanks to Tyler for your efforts, very much!

Error in loadNamespace(name) : there is no package called 'Rcpp'

I am trying to embed RInside to my application on win7 64-bit system but when I initialize an RInside:
Rin = new RInside(argc, argv);
the following message appears:
Error in loadNamespace(name) : there is no package called 'Rcpp'
This error only occurs with Windows.
I think you get that issue when your .libPaths() differ--in other words run the .libPaths() function to see the paths stored by R for its use. Then check where RInside is installed, and make sure Rcpp is installed there too. It is a setup issue.
In other words, it should work if you have Rcpp and RInside installed where the basic R libraries are. Otherwise you have to tell the (embedded) R session about the other location (and before it starts).
There are more Windows users on the list, so you could try asking on rcpp-devel.
First get your default library locations by command ".Library" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step1.
Now you are ready to install packages which have dependencies on Rcpp.
Dirk is right in this case, BUT if the .libPaths() does not work, then please also check if you have the latest packages.
I am posting this as an ancillary answer backup which I ran into with the shiny package backend switch of their code needing Rcpp!
In this case of getting the "no package" error message, I fixed it by:
Selecting devtools package and then using this line below. (if you don't have devtools then get it with install.packages("devtools")
devtools::install_github("rstudio/shiny")
The development version of the package handled this better, and added the package as a dependency.
Mods - I realize this is an answer to an old question, but I might help others not wasting an hour like I just did.
You might find it easy if the answers are for both R studio users and non R studio users.
R Studio users
First get your default library locations by command ".Library" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step 1, you will find another folder named library, paste the unzip folder in it.
Non R studio Users
First get your default library locations by command ".libPath" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step 1, you will find another folder named library, paste the unzip folder in it.
I was also getting this error while trying to run the 'ggplot' function from the ggplot2 package. After trying the suggestions posted here and elsewhere (checking file paths, restarting R, clearing out my environment, etc.) and encountering several other cryptic error messages, it turned out that I needed to download the latest version of base R for Windows (v3.4.1) and update my version of R-Studio to the latest version also (v1.0.153).
After doing this my 'ggplot' function was working again and I was able to render my figure from R Studio without any further issues.
I was also getting this message when trying to use ggplot. I first updating both my R for Windows to 3.4.3. Then updating R studio to version 1.1.423; then, updating all of the packages and being sure to access the R version 3.4.3 from R studio, I still got the message. None of these things fixed the error. I was ready to give up until I noticed that I was calling library(ggplot) and had ggplot::ggplot in my code. THIS WAS THE PROBLEM. I changed it to library(ggplot2) and the instance to ggplot2::ggplot(...). THIS FIXEd the problems.
I was facing a similar issue, and I simply installed the said package. It's working perfectly for me.

Resources