[R] Loading same libraries (old version & newest version) in r

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 12 09:05:28 CEST 2009


On Mon, 12 Oct 2009, Patrick Connolly wrote:

> On Mon, 12-Oct-2009 at 10:54AM +1100, Steven Kang wrote:
>
> |> Hi all,
> |>
> |> I require 2 RMySQL libraries in order to query from a database.
>
> You mean you require 2 RMySQL packages.  We must be pedantic to answer
> your question.
>
> |>
> |> 'RMySQL_0.7-4' (newest version) results in an error when more than 1 field
> |> is queried.
> |>
> |> ''RMySQL_0.5-11' (old version) resolves this issue where more than 1 field
> |> can be queried without any errors. However, other queries results in an
> |> error messeges (but no error messeges with 'RMySQL_0.7-4' package)
> |>
> |> Thus, I require two scripts each with different 'RMySQL' packages loaded to
> |> query from a database.
>
> If you put your *packages* in separate *libraries*, you can load the
> one you require using the lib.loc parameter, e.g.
>
> require(RMySQL, lib.loc = "/path/to/oldPackage")

Or library(): require() is just a wrapper.

> When you wish to use the one in /path/to/newPackage, unload the old
> one and change the lib.loc value.

Unfortunately that will not work (but starting a new session and 
loading from a different lib.loc will).  First, RMySQL has a 
namespace, so you need to unload the namespace, not just the package. 
But when you do that, there is AFAICS no .onUnload hook so the DLL 
remains loaded and will not be reloaded when the other version is 
loaded.  You could try playing with library.dynam.unload, but my hazy 
recollection is that did not work either (something to do with 
libmysqlclient only getting initialized once in a process).

I don't see an OS mentioned here, but basically do not believe that 
two versions are really needed: my guess is that this is Windows and 
you need to install RMySQL *from the sources* against your 
installation of MySQL.  There is a long history of binary 
incompatibility between versions of MySQL, even those which differ 
only by one in the 'patchlevel'.


> |>
> |> Are there any commands that will do the job (i.e. loading 2 different
> |> libraries from different folder) without having to click 'Pakages' tool bar
> |> in th RGui console?
> |>
> |> Your help in resolving this issue would be appreciated.
> |>
> |>
> |>
> |>
> |>
> |>
> |> Steven


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list