From murdoch.duncan at gmail.com  Wed Sep 22 17:31:09 2010
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Wed, 22 Sep 2010 11:31:09 -0400
Subject: [Rd] Possible bug or annoyance with library.dynam.unload()
In-Reply-To: <AANLkTimDqM3pdFH5-Ph9kW=CafapEt7aQB_4YjTC5+9X@mail.gmail.com>
References: <AANLkTik-Spu2SEAZjB3kSY1YoWFUhUy3NZ5-g3WRw_i2@mail.gmail.com>	<AANLkTimOnBLjWY9Qro88Pakd7_nTLibkqCkB1e=D7faQ@mail.gmail.com>	<4C98D038.8040507@gmail.com>
	<AANLkTimDqM3pdFH5-Ph9kW=CafapEt7aQB_4YjTC5+9X@mail.gmail.com>
Message-ID: <4C9A213D.7040006@gmail.com>

  On 22/09/2010 11:22 AM, Karl Forner wrote:
> Thanks Duncan for your suggestion.
>
> I could not find any package using dynamic library, namespaces and not the
> useDynLib pragma so
> I created a minimalistic package to demonstrate the problem.
> Please find attached a very small package foo (8.8k)

Your package depends on Rcpp, so I didn't try it in the alpha version of 
2.12.0 (Rcpp isn't available there in a Windows binary at the moment), 
but I did try it in R-patched.  With one minor change to your script 
(the lib.loc needs to be "local", not "local/" on Windows), I can 
reproduce the problem, and it looks like a bug to me.  Thanks for the 
report, I'll put it on the bugs page, and hopefully it will be fixed 
before the 2.12.0 release.

Duncan Murdoch

> Steps to reproduce the problem:
>
> * unarchive it ( tar zxvf foo_0.1.tar.gz )
> * cd foo
> * install it locally ( mkdir local; R CMD INSTALL -l local . )
> * R
> >  library(foo, lib.loc="local/")
> >.dynLibs()
> # there you should be able to see the foo.so lib, in my case
> /x05/people/m160508/workspace/foo/local/foo/libs/foo.so
>
> >  unloadNamespace("foo")
> .onUnload, libpath= local/fooWarning message:
> .onUnload failed in unloadNamespace() for 'foo', details:
>    call: library.dynam.unload("foo", libpath)
>    error: shared library 'foo' was not loaded
>
> #The libpath that the .onUnload() gets is "local/foo".
>
> #This fails:
> >library.dynam.unload("foo", "local/foo")
> Error in library.dynam.unload("foo", "local/foo") :
>    shared library 'foo' was not loaded
>
> # but if you use the absolute path it works:
> >library.dynam.unload("foo", "/x05/people/m160508/workspace/foo/local/foo")
>
> Karl
>
> On Tue, Sep 21, 2010 at 5:33 PM, Duncan Murdoch<murdoch.duncan at gmail.com>wrote:
>
> >   On 21/09/2010 10:38 AM, Karl Forner wrote:
> >
> >>  Hello,
> >>
> >>  I got no reply on this issue.
> >>  It is not critical and I could think of work-around, but it really looks
> >>  like a bug to me.
> >>  Should I file a bug-report instead of posting in this list ?
> >>
> >
> >  I'd probably post instructions for a reproducible example first.  Pick some
> >  CRAN package, tell us what to do with it to trigger the error, and then we
> >  can see if it's something special about your package or Roxygen or a general
> >  problem.
> >
> >  Duncan Murdoch
> >
> >   Thanks,
> >>
> >>  Karl
> >>
> >>  On Thu, Sep 16, 2010 at 6:11 PM, Karl Forner<karl.forner at gmail.com>
> >>   wrote:
> >>
> >>  >   Hello,
> >>  >
> >>  >   I have a package with a namespace. Because I use Roxygen that
> >>  overwrites
> >>  >   the NAMESPACE file each time it is run, I use a R/zzz.R file with
> >>  >   an .onLoad() and .onUnload() functions to take care of loading and
> >>  >   unloading my shared library.
> >>  >
> >>  >   The problem: if I load my library from a local directory, then the
> >>  >   unloading of the package fails, e.g:
> >>  >
> >>  >   # loads fine
> >>  >   >library(Foo, lib.loc=".Rcheck")
> >>  >
> >>  >   >unloadNamespace("Foo")
> >>  >   Warning message:
> >>  >   .onUnload failed in unloadNamespace() for 'Foo', details:
> >>  >     call: library.dynam.unload("Foo", libpath)
> >>  >     error: shared library 'Foo' was not loaded
> >>  >
> >>  >   # I traced it a little:
> >>  >   >library.dynam.unload("Foo", ".Rcheck/Foo")
> >>  >   Error in library.dynam.unload("Foo", ".Rcheck/Foo") :
> >>  >     shared library 'Foo' was not loaded
> >>  >
> >>  >   # using an absolute path works
> >>  >   >library.dynam.unload("Foo", "/home/toto/.Rcheck/Foo")
> >>  >
> >>  >
> >>  >   So from what I understand, the problem is either that the relative
> >>  libpath
> >>  >   is sent to the .onUnload() function instead of the absolute one,
> >>  >   or that library.dynam.unload() should be modified to handle the
> >>  relative
> >>  >   paths.
> >>  >
> >>  >   Am I missing something ? What should I do ?
> >>  >
> >>  >   Thanks,
> >>  >
> >>  >
> >>  >   Karl
> >>  >
> >>
> >>         [[alternative HTML version deleted]]
> >>
> >>  ______________________________________________
> >>  R-devel at r-project.org mailing list
> >>  https://stat.ethz.ch/mailman/listinfo/r-devel
> >>
> >
> >
>



[Rd] Possible bug or annoyance with library.dynam.unload()
Duncan Murdoch