Making R packages for installation by install.packages() - r

What is the difference between .tar.gz or .tgz files installed by R CMD install and install.packages()? I have made an example package with R CMD build, which I can currently install with R CMD install mypackage.tar.gz - and it works fine. I want to be able to install it through the install.packages() function (with a call like install.packages("mypackage.tar.gz",repos=NULL)). What additional steps do I need to take?

It depends on your OS. On Linux you can install your .tar.gz package with the command you specify. If you are on Mac OS X, you need to specify that you are installing from source package and not binary (see ?install.packages on a Mac). As Dirk said the .tgz packages are binary builds for Mac and you can build them on a Mac.
If you want to build the package for Windows see http://win-builder.r-project.org/, which is a web service for building binary packages from source.
If you are planning to submit your package to CRAN, but wan't to test is first see Rforge

I think the .tgz is the binary package on OS X, just like windows gets a binary .zip. Either one results from R CMD build.
So when you write "have made an example package with R CMD build, which I can currently install with R CMD install mypackage.tar.gz" you are inconsistent as the .tar.gz was the source and the result of the R CMD BUILD step. Start with the .tar.gz sources, make sure R CMD check and R CMD INSTALL work on them and then try R CMD binary.
Lastly, for install.packages() you need both the binary packages created by R CMD build --binary and a web-based repository containing file PACKAGES etc --- and as help(install.packages) says, see the R Installation and Administration manual for how to set up a repository.

Related

package 'lubridate' installation error: compilation failed for package 'lubridate' [duplicate]

A friend sent me along this great tutorial on webscraping The New York Times with R. I would really love to try it. However, the first step is to install a package called [RJSONIO][2] from source.
I know R reasonably well, but I have no idea how to install a package from source.
I'm running macOS (OS X).
If you have the file locally, then use install.packages() and set the repos=NULL:
install.packages(path_to_file, repos = NULL, type="source")
Where path_to_file would represent the full path and file name:
On Windows it will look something like this: "C:\\RJSONIO_0.2-3.tar.gz".
On UNIX it will look like this: "/home/blah/RJSONIO_0.2-3.tar.gz".
Download the source package, open Terminal.app, navigate to the directory where you currently have the file, and then execute:
R CMD INSTALL RJSONIO_0.2-3.tar.gz
Do note that this will only succeed when either: a) the package does not need compilation or b) the needed system tools for compilation are present. See: R for Mac OS X
You can install directly from the repository (note the type="source"):
install.packages("RJSONIO", repos = "http://www.omegahat.org/R", type="source")
A supplementarily handy (but trivial) tip for installing older version of packages from source.
First, if you call "install.packages", it always installs the latest package from repo. If you want to install the older version of packages, say for compatibility, you can call install.packages("url_to_source", repo=NULL, type="source"). For example:
install.packages("http://cran.r-project.org/src/contrib/Archive/RNetLogo/RNetLogo_0.9-6.tar.gz", repo=NULL, type="source")
Without manually downloading packages to the local disk and switching to the command line or installing from local disk, I found it is very convenient and simplify the call (one-step).
Plus: you can use this trick with devtools library's dev_mode, in order to manage different versions of packages:
Reference: doc devtools
From CRAN, you can install directly from a GitHub repository address. So if you want the package at https://github.com/twitter/AnomalyDetection, using
library(devtools)
install_github("twitter/AnomalyDetection")
does the trick.
In addition, you can build the binary package using the --binary option.
R CMD build --binary RJSONIO_0.2-3.tar.gz

Installation of R on redhat8 offline

I'm trying to have a way to download R for multiple clients with no internet access. Is there a way to download the .tar.gz files for all of R and its dependencies, so you don't need to download with internet connection? If there is a way to do that will R still show up with the "whereis R" command on linux? I'm trying to find a way in which I can give someone the downloaded files already within a package and they just run a .sh script that will download everything and R's dependencies for them with no real user intervention.
You may follow the manual on the topic "installing R under Unix-alike". Briefly: download the source and make it.
Download R and untar it
You can download the source from:
https://cran.r-project.org/sources.html
Then, use "tar" to extract the source and build it. Let's suppose that you want to install R 4.2:
tar -xf R-4.2.0.tar.gz
Make
Go to a directory where you will install R. Note that the path shouldn't contain spaces.
./configure
make
make check
If you want to install all the R tree (binaries, manuals, libraries...) use:
make install
Installing packages from source
To install packages in R, you can use the function install.packages() with the name of the file ('...tar.gz') to be installed and the argument "repos" set as "NULL"
You can also install the packages from a shell:
R CMD INSTALL -l /path/to/library packagename
Check the manual for additional information
You may also be interested in looking at this information:
https://cran.r-project.org/bin/linux/redhat/
https://cran.r-project.org/sources.html
The R manual describes how to install R from source in:
R-admin > Obtaining R > Getting and unpacking the sources
R-admin > Installing R under Unix-alikes

I want to install package xlsx on R 2.8.1 on windows but I have to use .tar.gz old package when I need .zip

For reasons that are too long to explain here, I must use R.2.8.1 (unfortunately). I need to have the xlsx package installed on it. Since I am on R 2.8.1, about ten years old, I can't use the latest version of xlsx but an older version, for instance xlsx_0.1.3 from 2010 seems a good choice. However the previous releases per R-CRAN policy are only available in tar.gz.
This is very unfortunate to me because I have to use RGui on windows which only accepts .Zip packages in installation. Therefore I tried the following stuff, in vain:
1-I tried to use Rcmd but I get the following error message:
C:\Program Files (x86)\R\R-2.8.1\bin>Rcmd INSTALL C:\Users\username\Downloads\xlsx_0.1.3.tar.gz
Can't use 'defined(#array)' (Maybe you should just omit the defined()?) at C:\PROGRA~2\R\R-28~1.1/bin/INSTALL line 42.
so I give up on this one.
2-Then I think that the best solution is to convert the package xlsx_0.1.3.tar.gz into a compatible xlsx_0.1.3.zip package by building it using R.2.8.1 but I can't make it. Here is one of the things I have tried so far.
I have unziped xlsx_0.1.3.tar.gz and I organized it in the following way, which brought me the furthest:
Documents\xlsx
Documents\xlsx\activate.bat
Documents\xlsx\build_xlsx.bat
Documents\xlsx\R
Documents\xlsx\R\inst
Documents\xlsx\R\man
Documents\xlsx\R\other
Documents\xlsx\R\R
Documents\xlsx\R\DESCRIPTION
Documents\xlsx\R\NAMESPACE
Documents\xlsx\R\NEWS
Documents\xlsx\R\WISHLIST
inside activate.bat, I wrote:
SET TMP=C:\Users\username\Documents\TOTO\xlsx\tmp
SET TEMP=%TMP%
SET RTOOLSPATH=C:\DEV_307\toto\Rtools
SET RPATH=C:\DEV\toto\R\R-2.8.1
SET PATH=%RTOOLSPATH%\bin;%RTOOLSPATH%\MinGW\bin;%RPATH%\bin;%PATH%
inside build_xlsx.bat, I wrote:
R CMD BUILD R
R CMD check --no-examples --no-tests R
R CMD build --docs=normal --binary R
Then I still get:
C:\Users\username\Documents\TOTO\xlsx>R CMD BUILD R
* checking for file 'R/DESCRIPTION' ... OK
* preparing 'R':
* checking DESCRIPTION meta-information ... OK
* installing the package to re-build vignettes
Can't use 'defined(#array)' (Maybe you should just omit the defined()?) at C:\DEV\toto\R\R-2.8.1/bin/INSTALL line 42.
ERROR
Installation failed.
Removing 'C:/Users/username/Documents/Rinst1210839349'
Thank you for your help
I can't include structured content in comments. This is really a comment.
The structure of source packages (which is what you have with xlsx_0.1.3.tar.gz if you pulled it from the CRAN archives) hasn't changed (much) since 2.8.1.
You'll also need to grab rJava_0.8-3.tar.gz and xlsxjars_0.2.0.tar.gz from the archive as xlsxjars + xlsx rely on rJava.
Extract each (since Windows R 2.8.1 seems to not grok gz files). They should make rJava, xlsxjars and xlsx directories each.
Move to the parent directory of both.
Run:
R CMD javareconf
R CMD build rJava
R CMD INSTALL rJava_0.8-3.zip # I believe this will be the name
R CMD build xlsxjars
R CMD INSTALL xlsxjars_0.2.0.zip
R CMD build xlsx
R CMD INSTALL xlsx_0.1.3.zip
and you should be gtg.

How to use R CMD Install without dependencies check?

I'm running R CMD INSTALL --build package on a windows computer. My package imports a couple of other packages which themselves depend on some more packages. I have all dependencies installed in the local r_libs folder and everything works.
Now sometimes I have the my package source code on a different windows computer. On this computer I don't have all the dependency packages installed.
When I try to use R CMD INSTALL --build package, I get the obvious "ERROR: dependencies 'package a', 'package b', etc, are not available for package".
My question is: Can I build the package using R CMD INSTALL --build without the dependency checks and without removing the Import and Depends entries in the DESCRIPTION file?
After consulting --help, I tried the --no-test-load option but no luck.
I reckon you want to build a .zip binary version of the package on a computer where not all dependencies are installed. And I'm afraid I'll have to disappoint you, as this won't be possible.
Building a binary package is done in two steps: first the package is installed from source (that's why you have to use R CMD INSTALL and then the created binaries are zipped in a convenient format for installation on a windows machine. The dependencies are checked at time of installation from source, and any missing dependencies will throw the error you're facing.
As R needs information from the dependencies at time of installation from source, you can't get around installing them before building the whole thing. This also makes sense. An installed package in R contains a set of .rds files which contain package information in a more convenient format for R. In order to create that information for the NAMESPACE file, it needs to be able to access the packages from which functions are imported. If not, it can't construct the correct information about the namespace.
So your only option is to install the dependencies on the computer you use to build. And if you actually want to use the package on that computer, you'll have to install those dependencies anyway.
More information:
R Internals : https://cran.r-project.org/doc/manuals/r-release/R-ints.html#Package-Structure
Writing R Extensions: https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-namespaces

R install Vennerable package on windows [duplicate]

This question already has answers here:
Cannot install R-forge package using install.packages
(4 answers)
Closed 8 years ago.
I am not able to install the Vennerable R package from https://r-forge.r-project.org/projects/vennerable/ on my Windows 7 with newest R (2.13.0).
I tried following:
installed from RGui and selecting R-Forge repos:
there was no Vennerable package in the list
installed from RGui using "install package from local zip file":
can not open compressed file 'Vennerable.tar.gz/DESCRIPTION'
converted tar.gz into zip and installed from RGui using "install package from local zip file":
can not open compressed file 'Vennerable.tar.gz/DESCRIPTION'
tried manual install: install.packages("D:/Downloads/Vennerable.tar.gz", repos = NULL)
can not open compressed file 'Vennerable.tar.gz/DESCRIPTION'
Error in install.packages : cannot open the connection
Note: there is a file DESCRIPTION.
What should I do to install this package?
Links on package page are dead (to either Windows build and package source).
You can checkout the source: open the terminal and run the following command
svn checkout svn://svn.r-forge.r-project.org/svnroot/vennerable
Then build without vignettes.
cd vennerable/pkg
R CMD build Vennerable/ --no-build-vignettes
and finally to install it:
R CMD INSTALL Vennerable_3.0.tar.gz
(Your build might be in a different name than Vennerable_3.0.tar.gz).
For me it generated the following error:
ERROR: dependencies ‘graph’, ‘RBGL’, ‘xtable’ are not available for package ‘Vennerable’
Then I had to go to R, run the following command:
install.packages(c("graph", "RBGL", "xtable"))
and then go back to the terminal and run the R CMD INSTALL ... command again.
Vennerable package has been updated and now version 2.1 is available from R-forge using
install.packages("Vennerable", repos="http://R-Forge.R-project.org")
I had the same problem and figured it out. The issue was with how the package is archived. There is a directory called 'Vennerable' within the top level directory which is called "Vennerable_2.2'. I unzipped the archive. Then I navigated to the 'Vennerable' subdirectory, and zipped that. Then I ran the installation using the new 'Vennerable.zip' archive. Worked like a charm.
If you have a tar.gz archive, you likely have the package's source files. You must build it first before installing the package. See section 1.3 of the Writing R Extensions manual
See also your other related question, where I provided this link to the built package for R 2.13.0 x86_64:
http://commondatastorage.googleapis.com/jthetzel-public/Vennerable_1.1.1.1.zip

Resources