embend a RInside c++ application under linux - r

I developed an application whose main graphical outputs relie on R through the very useful RInside. I would like to "deploy" my application under linux systems without having to systematically install R and the needed packages. For that purpose I simply copied all the R directory /usr/lib/R, all the needed .so library and set R_HOME variables to the correct path.
However, I get when executing:
Error in loadNamespace(name) : there is no package called ‘Rcpp’
Execution halted
While RInside is in the directory $R_HOME/site-library/RInside. I guess that I have more to do (and that my approach was quite naive). Does anyone already tries such a task and can help on what to do ?

Yes you need to install the other dependencies as well -- and Rcpp is needed to convert data seamlessly between R and C++.

Related

R: Error in install.packages : cannot open the connection

I was trying to install the package RINDSEL but I am unable to install it and I keep getting the following error:
Error in install.packages : cannot open the connection
I downloaded the package from:
rindsel_1.0_2.zip | Integrated Breeding Platform
and loaded it from the directory. Other packages from the directory can be installed but just not this one.
Is the package corrupt or could there be any other error?
I would really be grateful for any help. Thanks in advance
Rename the zip file RinSel Software into Rindsel. That's the name specified in the discription file.
Then, you can install the package in R with the command
install.packages("C:/path/to/Rindsel.zip",repos=NULL,type="win.binary")
That works fine... at first (!!!).
Problem with the Rindsel package is. It is quite old. It was build with R 2.13.1. Therefore, if you want to load the library which would be the next step to use the package in R you will get the error:
Problems building package (Error: "package has been build before R-3.0.0")
My suggestion: Contact the authors of the package and ask them if they can either provide the source file that you can build the package by yourself or if they can bundle the Rindsel package with a newer R version.
(Or you could try to hunt down an old R version and see if you can get the thing running with an old R... However, I would not seriously suggest to do that. It would probably result in conflicting dependencies with the other required packages...)
EDIT 15-02-2018: OP asked if one can build an R package with sources that are presumeably the Rindsel source files.
Yes, basically, you could do that. You would have to make a your own description and namespace file and put the source file in the R folder than invoke the command in R to build it....
But it's not neccessary with the script files provided by the link the OP posted.
OP, just run the scripts in R! It's quite easy.
Download the zip-file and extract it on your machine.
Go to that directory. The R command would be
setwd('path/to/your/directory')
Than run the R script, e.g, the KNIndex.r. It's simple:
source('KNIndex.r')
Then the script will run and produce some output / prompts.
For future readers,
I was able to fix the error by running RStudio with administrative privileges to get the command to work.
If that does not fix it, you might wish to try
Installing "r tools" if that is not installed already. That can be downloaded from
https://cran.r-project.org/bin/windows/Rtools/
Download a relevant package that you are trying to install (e.g., tidyverse_1.3.0.zip) from https://cran.rstudio.com/
and install that from local path
It can also be installed directly from the web using install.packages("https://cran.rstudio.com/bin/windows/contrib/4.0/tidyverse_1.3.0.zip")
I had the same problem. R was not able to extract and compile the package files to the default installation directory for some system-specific reasons (not R related).
I was able to fix this by specifying the installation directory of the package lib using:
install.packages("your package", lib = 'path/to your/required/installation/directory')
You can then load the package by specifying the lib.loc option while loading it:
library('your package', lib.loc='path/to your/required/installation/directory')
A better solution:
Create a new environment variable (if you are using windows) R_LIBS_USER with the following directory path/to your/required/installation/directory.
This will change the default installation directory of the packages and make it easier to load and install them without specifying the location everytime.

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.

How to reestablish the default library of an R project after updating Ubuntu?

I´m developing an R package in RStudio and a set a local library to contain all my packages. After installing some updates in my Ubuntu system, it seems that my R Project have lost track of the local library and is unable to load the libraries that were associated with it. If I try to Build & Reload the package with
R CMD INSTALL --no-multiarch --with-keep.source mypackage
The program tries to install to library '/usr/local/lib/R/site-library/' which is rejected with:
ERROR: No permission to install to directory '/usr/local/lib/R/site-library/'
As far as I remember, whenever I rebuilt my package, that line pointed to my local directory, where all my libraries were localted
installing to library ‘/home/user/R/x86_64-pc-linux-gnu-library/3.2’
It is clear that somehow R have lost track of the connection between the project and the libraries.
I tried re-including the path with
.LibPaths("/home/user/R/x86_64-pc-linux-gnu-library/3.2")
but, just after I rebuild the package again, the program created a 3.3 directory in x86_64-pc-linux-gnu-library. From there, it is unable to find the libraries that are associated to my program and throws another error:
ERROR: dependencies '...', '...' are not available for package "mypackage"
Is there a way to restore the program to the way it was before so I don't have to reinstall everything and start from scratch?
By default, R adds the major-minor version numbers to the library path (?.libPaths) for a good reason, assuming that the jump from 3.2 to 3.3 introduced efficiencies or incompatibilities. It is implied that this version jump requires new installation of packages.
If you override this, packages assembled in 3.2 may not always play nicely in 3.3. (I'm not going to test this theory, please report back if you can disprove this statement, I'm honestly interested!)
BTW: your call to .libPaths seems suspect: I don't know of a capital-L version, and when calling it you should include the previous path (unless you truly mean to omit the system R library paths entirely), such as:
.libPaths("/home/user/R/x86_64-pc-linux-gnu-library/3.2", .libPaths())
If you choose to do that, any bugs you may find in others' packages are possibly due to that incompatibility and should not necessarily be reported to developers.
Another option would be to re-install all packages from your 3.2 installation into your 3.3 library path. Something like this should help automate the process:
# to reinstall packages installed in R-3.2 subdir into R-3.3
install.packages(list.files(path = "~/R/x86_64-pc-linux-gnu-library/3.2"))

Error building package in R 3.1.2 w/ multiple third party DLL's

A colleague ported more than a thousand S functions and Fortran subroutines to R. The native R functions are contained in 5 .RData files and the Fortran subroutines are contained in 2 .dll files.
I can load these files into the R workspace using
for (i in 1:5){ load(list.files()[grep("RData",strsplit(list.files(),"\\W+"))][i]) }
for (i in 1:2){dyn.load(list.files()[grep("dll" ,strsplit(list.files(),"\\W+"))][i]) }
After some troubleshooting I know that the relationships between R code and the Fortran subroutines were already well established by the original author.
Now I want to create a package from these files because I'm unable to deploy my ioslides_presentations with these dll files since shinyapps.io is built with Linux. This is my first attempt at creating an R package, I don't intend to publish it to the CRAN, I'm only interested in generating a local zip file that I and my students can load.
MY PROCESS
After loading the functions in the workspace using the above code, I ran package.skeleton and system("R CMD build package") which successfully created "package_1.0.tar.gz". After completing the DESCRIPTION file, I put the .dll files I the src sub-directory and included useDynLib(DLL1), useDynLib(DLL2) in the NAMESPACE file.
However, when I run system("R CMD INSTALL build package_1.0.tar.gz") I get the following error:
Error in library.dynam(lib, package, package.lib) :
DLL 'package.dll' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
I've spent a great deal of time reading through "Writing R Extensions", "Advanced R" by Hadley Wickham, and the devtools documentation. Even so, I'm having difficulty deciphering useDynLib, .onLoad, Export, Call, and Makevars and which should be used for pre-compiled Fortran code.
I really don't want to parse through all of these functions to find which require export rules if I don't have to. I'd appreciate any help getting these .dll files loaded so I can finish creating this package
Thanks in advance,
Jason

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