R won't update the data.table package for me [duplicate] - 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.

Remote install of multiple R packages (with, without depends) from Ubuntu CLI

I have to perform a remote R installation on an Ubuntu 16.10 system. As part of this, I have to install specific packages on that host. I want to install these packages Rcmdr,list,ggplot2,afex,lsmeans. Since I am doing this remotely, I cannot use
sudo -i R
to first enter the R CLI and then install with install.packages(). Instead I must somehow install the packages from the Ubuntu CLI.
I found these links:
multiple R package installation with
install.packages()
R CMD INSTALL -l usage syntax to install multiple packages in
section
6.3
Use of repos parameter inside
install.packages()
However, some packages have dependencies:
The list package depends on utils and sandwich.
The Rcmdr package depends on grDevices, utils, splines, RcmdrMisc, car.
The ggplot2 package also has dependencies.
I would like to install only the packages Rcmdr,list,ggplot2 with all their dependencies. Normally, I would do it this way:
install.packages(c('Rcmdr','list','ggplot2'), dependencies=TRUE)
QUESTIONS
How do I specify the dependencies option in R CMD for one package
only? Is this the way to install them
R CMD INSTALL -l Rcmdr dependencies=TRUE, list dependencies=TRUE, \
ggplot2 dependencies=TRUE, afex, lsmeans
or this incorrect?
Also, how to I specify the repos parameter inside R CMD INSTALL -l?
EDIT
As per the first comment below, sudo is not needed above.i.e. sudo -i R can be replaced by R.
Regarding your questions:
Question 1
This may not be the best approach. Consider instead Rscript -e 'install.packages(...)' which is what R CMD INSTALL ... calls anyway. You have better control over options here. And read on...
Question 2
On all Ubuntu machines at work and home I do this via /etc/R/Rprofile.site via something like
## Example of Rprofile.site
local({
r <- getOption("repos")
r["CRAN"] <- "https://cloud.r-project.org"
r["ghrr"] <- "https://ghrr.github.io/drat"
options(repos = r)
})
where we usually add a third and network-local repo. You may just want CRAN here -- it uses the 'always-close to you' CDN administered by RStudio for the R Project and R Consortium. The ghrr drat is a helper repo I set up.
Question 3
sudo is not needed per something I add to the official Debian/Ubuntu package for R -- but you need to be a member of the group that owns /usr/local/lib/R/site-library.
Now, if I may, two more suggestions:
Littler
The r executable is available to you via sudo apt-get install r-cran-littler. I use it on the command-line; and you probably want to look into the basic install.r script and the extended install2.r. I tend to create a softlink from /usr/local/bin to the package directory for these and other (such as update.r). I have been running many (Ubuntu and Debian) machines like that for many years.
Michael Rutter repos, and Docker
We actually have about 3000 CRAN packages as binaries for Ubuntu so you could just do sudo apt-get install ... and all dependendies would get resolved. Look eg in this script of mine (which uses them on Travis) or some of the Docker files I maintain such as this one.

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

How do I install an R package from source?

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

Resources