How do i keep source files when using R's devtools library function 'install' - r

I am trying to build an R package (DESeq2) from source so that I can debug it. I've installed all the dependencies required and I'm following Hillary Parker's instructions for creating R packages. I'm running this on CentOS 6.6 using R-3.4.2.
I run :
library("devtools")
install("DESeq2", keep_source=TRUE)
It installs it in the directory with all my other R libraries. When I look at the installed DESeq2 library it is missing all the DESeq2/R/*.R and DESeq2/src/*.cpp files.
QUESTION : Where are these files and why didn't they get installed? This does not seem like the expected behavior.

R uses binary database format for installed packages to pack the objects into a database-alike file format for efficiency reasons (lazy loading). These database files (*.rdb and *.rdx) are stored in the R sub folder of the package installation path (see ?lazyLoad).
Even if
you are looking at the right place to find the installed package (use .libPaths() in R to find the installation folder)
and you have installed the package with the source code (like you did or
via install.packages("a_CRAN_package", INSTALL_opts = "--with-keep.source"))
you will not find R files in R folder there.
You can verify that the source code is available by picking one function name from the package and print it on the console. If you can see the source code (with comments) the package sources (R files) are available:
print(DeSeq2::any_function)
To make the source code available for debugging and stack traces you can set the option keep.source.pkgs = TRUE (see ?options) in your .Rprofile file or via an environment variable:
keep.source.pkgs:
As for keep.source, used only when packages are
installed. Defaults to FALSE unless the environment variable
R_KEEP_PKG_SOURCE is set to yes.
Note: The source code is available then only for newly installed and updated packages (not for already installed packages!).
For more details see: https://yetanothermathprogrammingconsultant.blogspot.de/2016/02/r-lazy-load-db-files.html

Related

Is there a way to 'install' R packages without running install.packages()?

We are testing how to run R in the cloud in a secure isolated environment that is blocked from CRAN and also cannot use packages.install(). We defined an environment which is based on R essentials Anaconda's bundle, still we would like to be able to customize it on demand with extra packages. Is there a way to be able to simulate packages.install(), e.g. by offline downloading the package, zip it, copy to the secure environment and unzipping it to a specific location in the library folder?
thanks!
You can download the package from CRAN as a zip and then transport it to the isolated PC as a file. For example, here is the link to dplyr on CRAN: https://cran.r-project.org/web/packages/dplyr/index.html
Then use the code below to install the local file:
install.packages("~/Downloads/dplyr_1.0.7.zip", repos = NULL)
On Windows you might require Rtools. At least there was a Warning about it but the package still installed.
For Linux machines, you can build the package from source using the tarball from the same page:
install.packages("~/Downloads/dplyr_1.0.7.tar.gz", repos = NULL, type = "source")
In both cases you need to take care of dependencies yourself as they are not checked while installing through this method (look at the "imports" field on the CRAN website for the package).

Copying old R packages from one linux server and installing them on a new server

I am trying to copy R packages from a directory on one linux server and install them on another. I started out by writing a script that would loop through a list of all the R packages I needed and install them. This worked for a majority of packages, but, since I am forced to utilize R 3.0.3, a significant number of packages are unavailable for this version of R. Meaning that R was trying to install the most recent versions of these specific packages.
I am trying to find a solution that does not involve me having to go through each package, find the version we are running on the old server, then going to CRAN and downloading the archived .tar.gz file.
Ideally, I would like to loop through the directory of R packages, make them all into .tar.gz files, move those files to the new server, and install them like that. However, I ran into the following issue when I tried to "build" one these packages.
R CMD build car
Read 1 item
* checking for file ‘car/DESCRIPTION’ ... OK
* preparing ‘car’:
* checking DESCRIPTION meta-information ... OK
Warning in file(con, "r") :
cannot open file 'man': No such file or directory
Error in file(con, "r") : cannot open the connection
ERROR
computing Rd index failed
I tried another using devtools::build('abind'), but this also failed with the same errors above.
Should I change my approach or is there something missing with what I am doing? Any help on this would be appreciated.
Your general approach won't work: tar.gz files contain the source for a package, but not all of it is installed when you install a package, so you can't recreate the tar.gz file from the installed files.
What might work if you didn't want to work with such an ancient version of R is to use Microsoft's CRAN "time machine" (https://mran.microsoft.com/timemachine), but I think it only goes back to R 3.2.3.
Copying the library might work, but binaries of those files are probably linked to system library files at particular locations, so I wouldn't trust it to be reliable.
I think your best option would be to update R to the current release (or maybe 3.5.3, the last patch release of the previous series), then just install current versions of the packages you want.
If this is impossible for some reason, then you're likely to have no choice but installing versions matching the ones you had installed. At least you can find versions automatically: the installed.packages() function returns a matrix with package name in column "Package" and its version in column "Version". Run that on the old system, then build them on the new system using the remotes::install_version() function (which claims to work on R back to 3.0.0, but I bet it hasn't been tested there lately).

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.

unable to access index for repository in R

I am on Windows 7 and I am using R Studio 0.99.902 with R3.3.1. When I am trying to install a package I get the Warnings:
Warning: unable to access index for repository http://cran.rstudio.com/src/contrib:
cannot open URL 'http://cran.rstudio.com/src/contrib/PACKAGES'
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/src/contrib:
cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES'
It is the first time I see it and I cannot solve it. Can anyone help me ?
This issue is likely caused by the package being too old or too new for your R version. For example, if a package is released during R-3.4.1, it will not be available for R-3.3.1. Packages which are removed from CRAN before your R version are also not available. The package DESCRIPTION file shows if there is a hard restriction on which R versions the package will run.
Search for the package's CRAN page and see its status. You may still be able to install the package by downloading the package source (the tar.gz file) and in RStudio selecting Install from: Package Archive File in the Tools/Install Packages... menu (or using install.packages with repos = NULL). Beware that the package is not available from CRAN for a reason; you may need to make some changes to the package for it to work correctly.
Running options(download.file.method="libcurl") then installing packages did the trick for me. You may find an answer here.
Please note that compiling from source for Windows requires the appropriate version of Rtools that is compatible with the R version you are working with. This list is available at the Rtools site:
https://cran.r-project.org/src/contrib/Archive/
If compilation from source is complicated, it is also possible to find the Windows-compiled binaries (.zip files) for older versions of R at:
https://cran-archive.r-project.org/bin/windows/contrib
This link is referenced by the ReadMe file available at the "regular" repository for Windows binaries for different versions of R, namely at:
https://cran.r-project.org/bin/windows/contrib
Once the zip file is downloaded, you can run the following R code line to install the package:
# Use repos=NULL so that the first argument is a path to the local zip file
# containing the binary package to install
# (as opposed to just the name of the package to install from the web)
install.packages("<local-path-to-downloaded-zip-file>", repos=NULL)

installing package from R-forge fails [duplicate]

This, question, is, asked, over, and, over, and, over,
on the R-sig-finance mailing list, but I do not think it has been asked on stackoverflow.
It goes like this:
Where can I obtain the latest version of package XYZ that is hosted on R-forge? I tried to install it with install.packages, but this is what happened:
> install.packages("XYZ",repos="http://r-forge.r-project.org")
Warning message: package ‘XYZ’ is not available (for R version 2.15.0)
Looking on the R-forge website for XYZ, I see that the package failed to build.
Therefore, there is no link to download the source. Is there any other way
to get the source code? Once I get the source code, how can I turn that into a
package that I can load with library("XYZ")?
R-Forge may fail to build a package for a few different reasons. It could be that
the documentation has not been updated to reflect recent changes in the code. Or,
it could be that some of the dependencies were not available at build time.
You can checkout the source code using svn. First, search for the project on the
R-Forge website and go to the project home page -- for example http://r-forge.r-project.org/projects/returnanalytics/
Click the SCM link to get to a page like this http://r-forge.r-project.org/scm/?group_id=579
This page will tell you the command to use to checkout the project. In this case you get
This project's SVN repository can be checked out through anonymous access with the following command(s).
svn checkout svn://svn.r-forge.r-project.org/svnroot/returnanalytics/
If you are on Windows, you probably want to download and install TortoiseSVN
Once you have installed TortoiseSVN, you can right click in a Windows Explorer window and select
"SVN checkout". In the "URL of repository:" field, enter everything except the
"svn checkout " part of the command that you found on R-Forge. In this case, you'd
enter "svn://svn.r-forge.r-project.org/svnroot/returnanalytics/".
When you click OK, the project will be downloaded into the current directory.
If you are on a UNIX-alike system (or if you installed the command line client tools
when you installed TortoiseSVN for Windows, which is not the default), you can
type the command that R-forge gave you in your terminal (System terminal, not the R terminal)
svn checkout svn://svn.r-forge.r-project.org/svnroot/returnanalytics/
That will create a new directory under the current working directory that
contains all of the files in the package. In the top level of that directory
will be a subdirectory called "pkg". This particular project (returnanalytics)
contains more than one package.
ls returnanalytics/pkg
#FactorAnalytics MPO PApages PerformanceAnalytics PortfolioAnalytics
But some R-forge projects only have a single package. e.g.
svn checkout svn://svn.r-forge.r-project.org/svnroot/random/
#Checked out revision 14.
ls random/pkg
#DESCRIPTION inst man NAMESPACE R
Now that you have a local copy all of the code, if you would like to be able to
install the package, you have to build it first.
A WORD OF CAUTION: Since R-Forge failed to build the package, there is a good chance
that there are problems with the package. Therefore, if you just build it, you may find
that some things do not work as expected. In particular, it is likely that there
is missing or incomplete documentation.
If you are on a UNIX-alike system, the package can be built and installed relatively easily. For a multi-package project like returnanalytics, if you want to install, e.g. the
PortfolioAnalytics package, you can do it like this
R --vanilla CMD INSTALL --build returnanalytics/pkg/PortfolioAnalytics
"PortfolioAnalytics" is the name of the directory that contains the package that
you want to build/install. For a single-package project, you can build and install like
this
R --vanilla CMD INSTALL --build random/pkg
If you would like to build/install a package on Windows, see this question and follow the two links that #JoshuaUlrich provided
More information can be found in R Installation and Administration, the R-Forge User Manual, and the SVN manual.
If (and only if) you have the appropriate toolchain for your OS, then this may succeed:
# First download source file to your working directory
# As an example use browser to download pkg:partykit from:
# http://download.r-forge.r-project.org/src/contrib/partykit_1.1-2.tar.gz
# Move to working directory
# Or in the case of returnanalytics (which is a bundle of packages):
# http://r-forge.r-project.org/R/?group_id=579 and download the tar.gz (source)
# Then in R:
install.packages( "partykit_1.1-2.tar.gz", repo=NULL, type="source")
# for the first of the ReturnAnalytics packages:
install.packages( "Dowd_0.11.tar.gz", repo=NULL, type="source")
These direction should be "cross-platform". I'm not sure the directions in the accepted answer are applicable to Macs (OSX). (I later confirmed that they do "work" on a Mac but found the process more involved that what I suggested above. They do result in a directory that do contain the packages in a form that should succeed with R --vanilla CMD INSTALL --build pathToEachPackageSeparately)
It is also possible that the current version of the package you are trying to install requires a newer version of R, for example, you may see error like:
"ERROR: this R is version 2.15.0, package 'PerformanceAnalytics' requires R >= 3.0.0"
then you can try to update your R
or, if you are facing the same situation with me, which is trying to use pqR (currently using R version 2.15), you can find the out-of-date achieved package here:
http://cran.at.r-project.org/src/contrib/Archive/PerformanceAnalytics/
You can get here from R-Forge packages page -> "Stable Release: Get PerformanceAnalytics 1.4.3541 from CRAN" -> Old sources: PerformanceAnalytics archive
for example, you will find package PerformanceAnalytics version 1.1.0 just requires R >= 2.14
Good luck
Alternatively, you can install the particular package from GitHub, if it has a repo at GitHub.
I ran install.packages('ggfortify'), and got
Warning message: “package ‘ggfortify’ is not available (for R version
3.3.2)”
ggfortify was the GitHub repo for the same package.
The devtools library allows you to install a package from GitHub directly with install_github('username/repo').
library(devtools)
install_github('sinhrks/ggfortify')

Resources