In Ubuntu Linux, the path to the global libraries is: /usr/local/lib/R/site-library/
To install there, you can do install.packages(c(‘foo’), ‘/usr/local/lib/R/site-library/’)
or take advantage of the built in variable: install.packages(c(‘foo’), .Library.site)
Check that .Library.site has the values you need.
You can also use R CMD INSTALL -l /path/to/library foo
(It didn’t work for me… 🙁 )
Below is a story about installing globally from source:
I was trying to run some Rook code in rApache, and discovered (via RApacheInfo, r-info) that the package wasn’t attached. Not being that familiar with either, I figured I needed to install a package globally.
The right way is described at stackoverflow by Dirk Eddelbuettel. littler is a scripting front end for R, so you can write R scripts as if they are regular scripts. (Normally, you need to go through the trouble of using here files.)
apt-get install littler
I copied the example scripts into my local bin
cp /usr/share/doc/littler/examples/* ~/bin
Then installed Rook
sudo ~/bin/install.r Rook
sudo service apache2 restart
Then, went back to the RApacheInfo page to look at the libraries. Rook was there! Yay!
But going back to the URL with the Rook script failed.
Tailing the server logs says rCharts isn’t installed.
So I then tried to install rCharts.
Had to do this:
sudo -s cd /usr/local/lib/R/site-library wget https://github.com/ramnathv/rCha... R CMD INSTALL -l . master.tar.gz service apache2 restart # and then when it works rm master.tar.gz
Turned out I needed more packages installed. Run these as root (or as recommended in the link, as a member of the staff group):
~/bin/install.r plyr ~/bin/install.r RJSONIO ~/bin/install.r whisker ~/bin/install.r yaml ~/bin/install.r zoo ~/bin/install.r DBI # the following might require the libmysqlclient-dev package ~/bin/install.r RMySQL # the next one doesn't work for R 3.0 ~/bin/install.r devtools
Note: I haven’t cleaned up my script and some of those libraries are extraneous… sorry.
All this stuff isn’t automated, so you should paste it into a script. You’ll need to run the update.r script later to update your packages.
Once that was done, the script could run a Hello, world program.
Getting the database going was a whole other task.
The rApache Config Lines
These follow the tutorial at the rApache site.
<Location /RApacheInfo> SetHandler r-info </Location> <Location /RToeChart> SetHandler r-handler RFileEval /home/johnk/Dropbox/www/foobar/firstplotrapache.R:Rook::Server$call(app) </Location>
The MySQL cnf file
There are several ways to pass password info to the application, but the way I like is MySQL options files, aka the my.cnf file. In Debian systems, they are in the files /etc/mysql/conf.d/*.cnf. Become root. Create a file called foobar.cnf:
[rstudio] user = user password = ***** host = localhost port = 3306 protocol = TCP database = foobar [rs-dbi] database = foobar
Then you have to set the file owner and mode:
chown www-data /etc/mysql/conf.d/foobar.cnf chmod go-rw /etc/mysql/conf.d/foobar.cnf
That’s my setup. I don’t think the rs-dbi section is required, but I have it there as a fallback.