[R] R CMD REMOVE etc. query

Prof. John C Nash nashjc at uottawa.ca
Thu Apr 15 19:45:15 CEST 2010


Brian Ripley pointed out that the library() documentation (third screen, however) says 
that library() and require() check current environment to see if a package is loaded and 
only load if it is not present. I may have oversimplified, and clarifications welcome. But 
this is clearly NOT what I want, since I need the latest package version to test.

Tentative solution is outlined, but suggestions welcome on string cleanup issue mentioned.

As I need to remove a package and its dependencies before reloading, I can use 
tool::pkgDepends to get a list.

I found that a character string extracted from the dependency vector gives 'invalid name' 
error in detach(). That is, I can create a variable myfoo="package:foo", but detach(myfoo) 
gives the error while typing detach("package:foo") works fine.  Workaround seems to be

    slist<-search()
    idx<-which(slist==myfoo)
    detach(idx)

There's still a nuisance issue of how to strip off  the (>=0.7.11) descriptors in the 
dependency list. strsplit() will work, but I seem to need to loop through the list to use 
it when only some of the packages are restricted by qualifiers.

If someone has already dealt with this type of issue, I'd be happy to know. For example, 
if there is a forceLoad() somewhere, it would save the effort above and could be useful 
for developers to ensure they are using the right version of a package.

JN



> From: Prof. John C Nash <nashjc_at_uottawa.ca>
> Date: Thu, 15 Apr 2010 10:17:46 -0400
> 
> I've been working on a fairly complex package that is a wrapper for several optimization routines. In this work, I've attempted to do the following:
> 
>     * edit the package code foo.R
>     * in a root terminal at the right directory location 

> R CMD REMOVE foo 

> R CMD INSTALL foo 
> 
> However, I don't get the right code. In fact, if I just do the remove,
> 
>      library(foo)
> 
> does not throw an error. If I stop my R session and restart it, I do.
> 
> Is this expected behaviour?
> 
> For information, I run scripted tests that start with
> 
>     rm(list=ls())
>     library(foo)
> 
> to ensure I'm getting "new" code each time.
> 
> If desired I can provide a minimal package to show this, but I expect that it is a known issue for which I've missed the documentation. Perhaps there is a command to reset the session. I did a brief search, but appropriate keywords pick up a lot of irrelevant material.
> 
> JN



More information about the R-help mailing list