Skip to content

installing/updating R packages: apt-get vs. install.packages() and .libPaths()

4 messages · Michael Friendly, Dirk Eddelbuettel

#
I recently had to rebuild my entire debian system to correct some severe 
dependency
conflicts and security issues.  I installed a new harddisk, linux kernel 
and started from
scratch, keeping my old disk mounted as /olddisk.  In the process I 
switched from unstable
to stable distros as recommended by a local sysadmin to avoid such 
problems in the future.

Now I want to be able to install and update R and R packages with ease 
and with minimal
confusion about different versions in different libraries, so that I can 
(a) install new
packages in a consistent way with my current R version, (b)  install a new
R version with apt-get install r-base, ...  (c) run update.packages() or 
something equivalent
to update all the packages coherently. 

 I'm confused about where things go based on apt-get install 
{r-base,r-cran}* vs install.packages()
and whether I am running as root vs me.  If I want to update.packages() 
I don't want to have
to worry about whether I am currently root or me -- I just want to be 
*me* and have it work.

 > .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
[3] "/usr/lib/R/library"
 >

"/usr/lib/R/library"   for apt-get install r-base, as root
"/usr/lib/R/site-library"    for apt-get install r-cran, as root
"/usr/local/lib/R/site-library"   for install.packages() as {me,root}

My machine is single user; should I just give myself chmod g+w privs 
under  /usr/lib/R/site-library
and maybe /usr/lib/R/library?  What is the recommended discipline?

thx,
#
[ Delayed, and the manually approved as Michael posted without being
  subscribed under this address. Please consider subscribing.  --Dirk ]

Hi Michael,
On 10 March 2006 at 11:14, Michael Friendly wrote:
| I recently had to rebuild my entire debian system to correct some severe 
| dependency 
| conflicts and security issues. 

That should only happen by accident or some sort of negligence. I have
systems that I continuously upgraded for many, many years without problems.
Mind you they are also behind firewalls and not quite as visible as a
yorku.ca machine ...

| I installed a new harddisk, linux kernel 
| and started from
| scratch, keeping my old disk mounted as /olddisk.  In the process I 
| switched from unstable
| to stable distros as recommended by a local sysadmin to avoid such 
| problems in the future.
| 
| Now I want to be able to install and update R and R packages with ease 
| and with minimal
| confusion about different versions in different libraries, 

No problem so far.

| so that I can 
| (a) install new packages in a consistent way with my current R version, 

Ok. More on that below.

| (b)  install a new R version with apt-get install r-base, ...  

That is in conflict with your approach from the very first paragraph.  By the
suggestion of your sysadmin, you cannot install new R version as they may
create 'severe dependency conflicts and security issues'.  All kidding aside,
you either believe that 

  I)  you want a stable system so you don't install new software, not
      even R, or

  II) you need current software, maybe only R, so you're willing to make
      compromises.

II) is possible via the backports of current R version that are on CRAN. Just
don't tell your sysadmin....  If you point to the apt-get'able archive
provided by CRAN you get new Debian packages of new R releases withins days
of the R release.

| (c) run update.packages() or something equivalent
| to update all the packages coherently. 

Also possible.

|  I'm confused about where things go based on apt-get install 
| {r-base,r-cran}* vs install.packages()
| and whether I am running as root vs me.  If I want to update.packages() 
| I don't want to have
| to worry about whether I am currently root or me -- I just want to be 
| *me* and have it work.

That works _provided you prepare your territory__. This is unix, so "you"
can only write there if your root let's you write. So you could for example

i)   add yourself to group adm in /etc/groups
ii)  chgrp adm /usr/local/lib/R/site-library/
iii) chmod g+w /usr/local/lib/R/site-library/

Now you should be able to say (inside R) 

	> update.packages(lib.loc="/usr/local/lib/R/site-library/")

In fact, I just did that.  You may need ii) and iii) with an added -R so that
you are allowed to overwrite previously installed versions, if any:

iv)  chgrp -R adm /usr/local/lib/R/site-library/
v)   chmod -R g+w /usr/local/lib/R/site-library/

|  > .libPaths()
| [1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
| [3] "/usr/lib/R/library"
|  >
| 
| "/usr/lib/R/library"   for apt-get install r-base, as root

Per a suggestion by Fritz and Kurt at one of the Vienna conferences, this
directory is reserved for everything from r-base-core and r-recommended (ie
boot, MASS, ...) and *nothing* else. So these would get updated via apt-get
and dpkg.

| "/usr/lib/R/site-library"    for apt-get install r-cran, as root

Per a suggestion by Fritz and Kurt at one of the Vienna conferences, this
directory is reserved for whatever R packages _Debian_ adds to the system.
So these would get updated via apt-get and dpkg as well.

| "/usr/local/lib/R/site-library"   for install.packages() as {me,root}

Per a suggestion by Fritz and Kurt at one of the Vienna conferences, this
directory is reserved for whatever the local user/admin installs.  I used to
do that as root, but the method I suggest above is actually nicer.  So yes,
you can do that provided you (as root) give yourself (as you) the proper
permissions.

| My machine is single user; should I just give myself chmod g+w privs 
| under  /usr/lib/R/site-library
| and maybe /usr/lib/R/library?  What is the recommended discipline?

Only for /usr/local/lib/R/ as you need root permissions (or at least sudo) to
interact with apt-get / dpkg anyway.

I hope this is of help and wasn;t too terse.  We should expand this where
needed and maybe post it on the R Wiki or maybe even polish it up for a quick
one-pager in R News...

Best regards,  Dirk
1 day later
#
Dirk Eddelbuettel wrote:

            
[I've subscribed 3 times, always with the same outgoing email address
But I never get a confirmation, or the digest postings I requested.]

Aparently, I wasn't the only one confused:
Jeremy wrote:
[I think the point here was not that debian didn't appear in the FAQ,
but rather that the information there was not sufficiently detailed.]

I would recommend the following:

1) In the R-FAQ, add the the lines:

More details on installing and administering R on debian linux may be
found at

     <link>http://cran.r-project.org/bin/linux/debian/README</link>

2) Add a section to the above README along the following lines of:
(feel free to edit in any way)

* DEBIAN ADMINISTRATION AND MAINTENANCE

The recommended policy for installing and maintaining R on debian linux 
is as follows:

    *  The r-base-core and r-recommended debian packages are normally 
installed and updated using apt-get (as root) to /usr/lib/R/library.

    *  Other debian packages (e.g., r-cran-*) are normally installed and 
updated using apt-get (as root) to /usr/lib/R/site-library.

    *  Still other packages may be installed by the local user/admin
from source or using install.packeges() to 
/usr/local/lib/R/site-library/.  This depends on local policy and 
setting the proper permissions.

    *  Users are always free to install packages in $HOME/lib/R/library
(or elsewhere).  This requires adding any such library to the .lib.paths
list, e.g., in .Rprofile ...
OK, but implicit in my original post was the question of what happens 
when there are packages to be upgraded in more than one library.  If I
specify lib.loc="/usr/local/lib/R/site-library/", then, presumably the
r-cran-* packages will be upgraded there, rather than in 
/usr/lib/R/site-library vs. upgrading with apt-get.   The help for 
update.packages is mute on what happens when lib.loc=NULL.

  lib.loc: character vector describing the location of R library trees
           to search through (and update packages therein).
This was certainly helpful.  Yes, something on the R Wiki or R News 
would be useful.

  
    
#
Michael,

I just had to approve another post of yours ....
On 12 March 2006 at 12:13, Michael Friendly wrote:
| 
|
| Dirk Eddelbuettel wrote:
| 
| > [ Delayed, and the manually approved as Michael posted without being
| >   subscribed under this address. Please consider subscribing.  --Dirk ]
| 
| [I've subscribed 3 times, always with the same outgoing email address
| > Your subscription request has been received, and will soon be acted upon. Depending on the configuration of this mailing list, your subscription request may have to be first confirmed by you via email, or approved by the list moderator. If confirmation is required, you will soon get a confirmation email which contains further instructions.
| 
| But I never get a confirmation, or the digest postings I requested.]

I would take that to mean that you never got the subscription finalised. It
works with a handshake mechanism via email. Maybe York U blocked the reply,
maybe your spam filter ate it. I do not know.  I can however confirm that
'friendly at yorku.ca' is not shown as a list member.

So I just subscribed you manually.  Obviously, this doesn't scale well and I
do not intend to offer that service for everybody who fails to subscribe
manually.

| Aparently, I wasn't the only one confused:
| Jeremy wrote:
| > I couldn't find anything on the R FAQ's mentioning Debian
| > specifically.  And a simple search for 'upgrade' in the FAQ also
| > turned up nothing.  I even used Google to search for a way to upgrade
| > R using CRAN, with no relevant results.  After a little bit of
| > searching around the CRAN site I found this :
| > 
| > http://cran.r-project.org/bin/linux/debian/README
| > 
| > Which was all the information I needed.  Thanks for all the help.
| > 
| > Jeremy

That is an unrelated issue of someone failing to read the FAQ. I see no point
in bringing it up here, really.

| [I think the point here was not that debian didn't appear in the FAQ,
| but rather that the information there was not sufficiently detailed.]
| 
| I would recommend the following:
| 
| 1) In the R-FAQ, add the the lines:

For matters related to the FAQ, please email Kurt.Hornik at R-Project.org about
this (and I will CC him now). I have no influence on the R FAQ. I merely run
two R-related lists per an invitation by Martin M., and maintain a number of
Debian R packages.

| More details on installing and administering R on debian linux may be
| found at
| 
|      <link>http://cran.r-project.org/bin/linux/debian/README</link>
| 
| 2) Add a section to the above README along the following lines of:
| (feel free to edit in any way)

I think for changes to the README, a diff or a new version emailed to
cran at r-project.org is the best way to go about it.
 
| * DEBIAN ADMINISTRATION AND MAINTENANCE
| 
| The recommended policy for installing and maintaining R on debian linux 
| is as follows:
| 
|     *  The r-base-core and r-recommended debian packages are normally 
| installed and updated using apt-get (as root) to /usr/lib/R/library.
| 
|     *  Other debian packages (e.g., r-cran-*) are normally installed and 
| updated using apt-get (as root) to /usr/lib/R/site-library.
| 
|     *  Still other packages may be installed by the local user/admin
| from source or using install.packeges() to 
| /usr/local/lib/R/site-library/.  This depends on local policy and 
| setting the proper permissions.
| 
|     *  Users are always free to install packages in $HOME/lib/R/library
| (or elsewhere).  This requires adding any such library to the .lib.paths
| list, e.g., in .Rprofile ...
| 
| > 
| > |  I'm confused about where things go based on apt-get install 
| > | {r-base,r-cran}* vs install.packages()
| > | and whether I am running as root vs me.  If I want to update.packages() 
| > | I don't want to have
| > | to worry about whether I am currently root or me -- I just want to be 
| > | *me* and have it work.
| > 
| > That works _provided you prepare your territory__. This is unix, so "you"
| > can only write there if your root let's you write. So you could for example
| > 
| > i)   add yourself to group adm in /etc/groups
| > ii)  chgrp adm /usr/local/lib/R/site-library/
| > iii) chmod g+w /usr/local/lib/R/site-library/
| > 
| > Now you should be able to say (inside R) 
| > 
| > 	> update.packages(lib.loc="/usr/local/lib/R/site-library/")
| 
| OK, but implicit in my original post was the question of what happens 
| when there are packages to be upgraded in more than one library.  If I

I think you should strive to not install more than once. One would have to
see what R does if confronted with several instances of the same package
(possibly in several versions).

Gregor posted a script to test for this too.

| specify lib.loc="/usr/local/lib/R/site-library/", then, presumably the
| r-cran-* packages will be upgraded there, rather than in 
| /usr/lib/R/site-library vs. upgrading with apt-get.   The help for 
| update.packages is mute on what happens when lib.loc=NULL.
| 
|   lib.loc: character vector describing the location of R library trees
|            to search through (and update packages therein).
| 
| 
| 
| > In fact, I just did that.  You may need ii) and iii) with an added -R so that
| > you are allowed to overwrite previously installed versions, if any:
| > 
| > iv)  chgrp -R adm /usr/local/lib/R/site-library/
| > v)   chmod -R g+w /usr/local/lib/R/site-library/
| > 
| > |  > .libPaths()
| > | [1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
| > | [3] "/usr/lib/R/library"
| > |  >
| > | 
| > | "/usr/lib/R/library"   for apt-get install r-base, as root
| > 
| > Per a suggestion by Fritz and Kurt at one of the Vienna conferences, this
| > directory is reserved for everything from r-base-core and r-recommended (ie
| > boot, MASS, ...) and *nothing* else. So these would get updated via apt-get
| > and dpkg.
| > 
| > | "/usr/lib/R/site-library"    for apt-get install r-cran, as root
| > 
| > Per a suggestion by Fritz and Kurt at one of the Vienna conferences, this
| > directory is reserved for whatever R packages _Debian_ adds to the system.
| > So these would get updated via apt-get and dpkg as well.
| > 
| > | "/usr/local/lib/R/site-library"   for install.packages() as {me,root}
| > 
| > Per a suggestion by Fritz and Kurt at one of the Vienna conferences, this
| > directory is reserved for whatever the local user/admin installs.  I used to
| > do that as root, but the method I suggest above is actually nicer.  So yes,
| > you can do that provided you (as root) give yourself (as you) the proper
| > permissions.
| > 
| > | My machine is single user; should I just give myself chmod g+w privs 
| > | under  /usr/lib/R/site-library
| > | and maybe /usr/lib/R/library?  What is the recommended discipline?
| > 
| > Only for /usr/local/lib/R/ as you need root permissions (or at least sudo) to
| > interact with apt-get / dpkg anyway.
| > 
| > I hope this is of help and wasn;t too terse.  We should expand this where
| > needed and maybe post it on the R Wiki or maybe even polish it up for a quick
| > one-pager in R News...
| 
| This was certainly helpful.  Yes, something on the R Wiki or R News 
| would be useful.

Could you possibly volunteer to edit the Wiki along these lines?  That is a
file that is open to all of us, so we should use it.

Hope this helps,  Dirk

| > Best regards,  Dirk
| > 
| 
| -- 
| Michael Friendly     Email: friendly AT yorku DOT ca
| Professor, Psychology Dept.
| York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
| 4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
| Toronto, ONT  M3J 1P3 CANADA