I developed an answer related to the approach here, but which uses only base R (you don't need XML
or devtools
or anything). It also potentially handles some contingencies that may not be addressed by the solution I linked to from the other question. Since it was around 100 lines of code, rather than just post a huge function here, I rolled it into a package oldr
you can get from GitHub here:
oldr
package GitHub repo
The package has just one exported function, install.compatible.packages()
. I have tested it on Ubuntu 18.04. I installed R 3.1.0 and installed tm
(and its dependencies). The current version of tm
requires R 3.2.0, so wouldn't be available via install.packages()
, but my function allows its installation:
> oldr::install.compatible.packages("NLP")
Installing package into ‘/home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘NLP’ ...
** package ‘NLP’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (NLP)
> oldr::install.compatible.packages("slam")
Installing package into ‘/home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘slam’ ...
** package ‘slam’ successfully unpacked and MD5 sums checked
** libs
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c apply.c -o apply.o
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c grouped.c -o grouped.o
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c sparse.c -o sparse.o
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c util.c -o util.o
gcc -shared -L/usr/local/lib -o slam.so apply.o grouped.o sparse.o util.o -L/opt/R/3.1.0/lib/R/lib -lRblas -lgfortran -lm -lquadmath -L/opt/R/3.1.0/lib/R/lib -lR
installing to /home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1/slam/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (slam)
> oldr::install.compatible.packages("tm")
Installing package into ‘/home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘tm’ ...
** package ‘tm’ successfully unpacked and MD5 sums checked
** libs
gcc -I/opt/R/3.1.0/lib/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c copy.c -o copy.o
gcc -shared -L/usr/local/lib -o tm.so copy.o -L/opt/R/3.1.0/lib/R/lib -lR
installing to /home/duckmayr/R/x86_64-unknown-linux-gnu-library/3.1/tm/libs
** R
** data
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (tm)
Update: Testing on Windows
I now have also had the chance to test on Windows (8.1), and everything worked smoothly for installing tm
to an old version of R (v. 3.1.0):
> oldr::install.compatible.packages("NLP")
Installing package into ‘C:/Users/User/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://mirror.las.iastate.edu/CRAN/bin/windows/contrib/3.1/NLP_0.1-9.zip'
Content type 'application/zip' length 278699 bytes (272 Kb)
opened URL
downloaded 272 Kb
package ‘NLP’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\User\AppData\Local\Temp\RtmpojDNlF\downloaded_packages
> oldr::install.compatible.packages("slam")
Installing package into ‘C:/Users/User/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://mirror.las.iastate.edu/CRAN/bin/windows/contrib/3.1/slam_0.1-32.zip'
Content type 'application/zip' length 111528 bytes (108 Kb)
opened URL
downloaded 108 Kb
package ‘slam’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\User\AppData\Local\Temp\RtmpojDNlF\downloaded_packages
> oldr::install.compatible.packages("tm")
Installing package into ‘C:/Users/User/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://mirror.las.iastate.edu/CRAN/bin/windows/contrib/3.1/tm_0.6-2.zip'
Content type 'application/zip' length 710798 bytes (694 Kb)
opened URL
downloaded 694 Kb
package ‘tm’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\User\AppData\Local\Temp\RtmpojDNlF\downloaded_packages
Update: Additional Parameters
Now users can specify which version of R to attempt installation for (R_version
parameter), and which directory to install packages to (lib
parameter), which could be useful for testing or other purposes.