How do I install an R package from source? - r

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

If you have source code you wrote yourself, downloaded (cloned) from GitHub, or otherwise copied or moved to your computer from some other source, a nice simple way to install the package/library is:
In R
It's as simple as:
# install.packages("devtools")
devtools::install('path/to/package')
From terminal
From here, you can clone a GitHub repo and install it with:
git clone https://github.com/user/repo.git
R -e "install.packages('devtools');devtools::install('path/to/package')"
Or if you already have devtools installed, you can skip that first bit and just clone the repo and run:
R -e "devtools::install('path/to/package')"
Note that if you're on ubuntu, install these system libraries before installing devtools (or devtools won't install properly).
apt-get update
apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev -y

Related

Install packages during build of rocker/tidyverse docker image

I am building a docker image using rocker/tidyverse.
My Dockerfile:
FROM rocker/tidyverse:4.0.4
COPY train.R /train.R
COPY install.R /install.R
COPY entrypoint.sh /entrypoint.sh
# pre install the packages during build
RUN Rscript install.R
Here's the install.r script from above:
install.packages('pacman')
pacman::p_load(lubridate, Metrics, foreach)
Also tried a variation of this with just install.packages(<packagename>) for each of the packages in the install.r script.
When I attempt to build I get an error message:
docker-compose build rtrain
Step 5/5 : RUN Rscript install.R
---> Running in 3ebf7ab0c227
Installing package into '/usr/local/lib/R/site-library'
(as 'lib' is unspecified)
Warning: unable to access index for repository https://packagemanager.rstudio.com/cran/__linux__/focal/2021-03-30/src/contrib:
cannot open URL 'https://packagemanager.rstudio.com/cran/__linux__/focal/2021-03-30/src/contrib/PACKAGES'
Warning message:
package 'pacman' is not available for this version of R
If I remove RUN Rscript install.r from build but instead run the image and then exec into it, I am able to run it with just Rsctipt install.r. It's only during build that this happens.
On the page on the first url I linked to above there's a mention of script install2.r but I could not find any mention of this anywhere. The full blurb:
NOTES
do not use apt-get install r-cran-* to install R packages on this stack . The requested R version and all R packages are installed from source in the version-stable stack. Installing R packages from apt (e.g. the r-cran-* packages) will install the version of R and versions of the packages that were built for the stable debian release (e.g. debian:stretch ), giving you a second version of R and different packages. Please install R packages from source using the install.packages() R function (or the install2.r script), and use apt only to install necessary system libraries (e.g. libxml2 ). If you would prefer to install only the latest verions of packages from pre-built binaries using apt-get , consider using the r-base stack instead.
Underlining I did try modifying install.r to just be repeated rows of install.packages("lubridate") install.packages("Metrics") and install.packages("foreach") but the same error happens.
How can I install packages during build using this image?
Changing my version to 4.0.1 solved my problem:
FROM rocker/tidyverse:4.0.1
Then everything else the same, worked.

How to install libxml2 package in R if it's not available for my version?

I wanted to install "DESeq2" package in R, but it was missing the xml2-config file. I found somewhere that it can be obtained by installing the libxml2 package, but when I tried it gives error that it's not available for R version 3.4.2. Anyone has idea what to do?
You can install the dev version: devtools::install_github("r-lib/xml2")
After running what #amarchin wrote it didn't work instantly but R suggested to install libxml2-dev. So I run: sudo apt-get install libxml2-dev in Terminal.
And then in R console I typed the code from #amarchin: devtools::install_github("r-lib/xml2")
And it worked :)

R won't update the data.table package for me [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
If you have source code you wrote yourself, downloaded (cloned) from GitHub, or otherwise copied or moved to your computer from some other source, a nice simple way to install the package/library is:
In R
It's as simple as:
# install.packages("devtools")
devtools::install('path/to/package')
From terminal
From here, you can clone a GitHub repo and install it with:
git clone https://github.com/user/repo.git
R -e "install.packages('devtools');devtools::install('path/to/package')"
Or if you already have devtools installed, you can skip that first bit and just clone the repo and run:
R -e "devtools::install('path/to/package')"
Note that if you're on ubuntu, install these system libraries before installing devtools (or devtools won't install properly).
apt-get update
apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev -y

How to install "arm" package in R/Rstudio for downloading it directly and not from the Packages ->Install interface? [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
If you have source code you wrote yourself, downloaded (cloned) from GitHub, or otherwise copied or moved to your computer from some other source, a nice simple way to install the package/library is:
In R
It's as simple as:
# install.packages("devtools")
devtools::install('path/to/package')
From terminal
From here, you can clone a GitHub repo and install it with:
git clone https://github.com/user/repo.git
R -e "install.packages('devtools');devtools::install('path/to/package')"
Or if you already have devtools installed, you can skip that first bit and just clone the repo and run:
R -e "devtools::install('path/to/package')"
Note that if you're on ubuntu, install these system libraries before installing devtools (or devtools won't install properly).
apt-get update
apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev -y

Tktable : could not be found in R

I try to use tcltk in R, but the package Tktable could not be found.
> library("tcltk")
Loading Tcl/Tk... OK
> tclRequire("Tktable")
[1] FALSE
Warning :
In tclRequire("Tktable") : the package Tcl 'Tktable' is not found
When I install R (r-base-core) all this linux package are installed too :
tcl install
tcl-dev install
tcl8.5 install
tcl8.5-dev install
tcllib install
tk install
tk-dev install
tk8.5 install
tk8.5-dev install
tklib install
I tried to install manually libtktable2.9, and those packages are automatically installed :
libtktable2.9:i386 install
tk8.4:i386 install
tcl8.4:i386 install
I tried the fonction addTclPath in R (with different path, because I dont really understand where is the tcl location...), but nothing changes.
I saw similar posts on few forums but no answer yet.
Any idea?
http://bioinf.wehi.edu.au/affylmGUI/#testBWTk describes installing Tktable.
To install Tktable download from http://tktable.sourceforge.net. From
this site, select "File Distributions, select the "tktable" link,
select the latest version (currently 2.10), then select the tar.gz
file (currently "Tktable2.10.tar.gz"). Save it to a suitable location,
unzip and untar it (Example command is "tar zxf Tktable2.10.tar.gz").
look in the Tktable directory and read the README.txt file
installation instructions.
To get Tktable to install on debian, I installed this first
sudo apt-get install tcl-dev tk-dev mesa-common-dev libjpeg-dev libtogl-dev
On Ubuntu 18.04, I could just install the package tk-table
sudo apt install tk-table
Just for documentation purposes for other readers:
Windows users should be aware that the Tcl extensions ‘BWidget’ and
‘Tktable’ which are included with the R for Windows installer are
extensions and do need to be declared. ‘Tktable’ does ship as part of
the Tcl/Tk provided on CRAN for Mac OS X, but you will need to tell
your users how to make use of it:
> addTclPath('/usr/local/lib/Tktable2.9')
> tclRequire('Tktable')
<Tcl> 2.9
So there is no need for an extra tcl/tk or tktable installation.
Source: http://www.pqr-project.org/R-exts.html

Resources