[R-SIG-Mac] Problems with dyn.unload of shared object from Fortran code and command line R

Kyle Baron kyleb at metrumrg.com
Wed Nov 27 21:22:26 CET 2013


Hi -

I am developing an R package (OSX 10.8.5, R version 3.0.2) with both C
and fortran code  and noticed strange behavior when trying to unload
the
shared-object after dyn.load (part of devtools development workflow).
When I try to dyn.unload,  the R prompt appears again, but I can't run
any more commands and I find the R process is taking 100% cpu (per
htop).

I get the problem behavior when using command line R (but not R.app or
Rstudio) and can't recreate it on Ubuntu.  Also, this only seems to
happen with fortran code, not C code (a simple C example compiles,
loads and unloads fine).

So my package seems to work fine, but I get into trouble with
dyn.unload in the development cycle when fortran code is in the mix.
Wondering why this is happening and how I can setup commandline R on
OSX to handle this dyn.unload more gracefully (as R.app does).

An example and R info below.

Thank you in advance,
Kyle

Kyle Baron
Metrum Research Group
www.metrumrg.com



I was able to recreate the issue using this toy fortran code:

C     *****************************************
C     http://users.stat.umn.edu/~geyer/rc/bar.f
      subroutine bar(n, x)

      integer n
      double precision x(n)
      integer i

      do 100 i = 1, n
          x(i) = x(i) ** 2
  100 continue

      end
C     end bar.f
C     ******************************************


bash$ R CMD SHLIB bar.f
llvm-gcc-4.2 -arch x86_64 -std=gnu99 -dynamiclib
-Wl,-headerpad_max_install_names -undefined dynamic_lookup
-single_module -multiply_defined suppress -L/usr/local/lib
-L/usr/local/lib -o bar.so bar.o
-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64
-L/usr/local/lib/x86_64 -L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3
-lgfortran -F/Library/Frameworks/R.framework/.. -framework R
-Wl,-framework -Wl,CoreFoundation

R:
> dyn.load("bar.so")
> is.loaded("bar")
[1] TRUE
> dyn.unload("bar.so")
> is.loaded("bar") ## FALSE if R.app, Rstudio, can't run the command if commandline R on OSX and must restart R


> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     grDevices utils     datasets  graphics  methods   base



More information about the R-SIG-Mac mailing list