Hello I managed to find what was wrong and it has nothing to do with .First.lib. The clue was in NAMESPACE and in the way the fortran was called (don't use dyn.load).
I thank the author of the package digest where I found the lines that help me to crack what was wrong and Uwe Ligges for pushing me hard. Cheers Ed -----Original Message----- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: Saturday, August 20, 2011 10:38 AM To: Eduardo Mendes Cc: r-help@r-project.org Subject: Re: [R] Build a package - check error On 20.08.2011 00:41, Eduardo Mendes wrote: > Hi > > I have modified the path to > > dyn.load(paste(Sys.getenv("R_LIBS_USER"),"/fortran/src/fortran.so",sep > ="")) Hmmm, looks like you never took a look into the relevant manual "Writing R Extensions" nor in the help files I cited below. ?.First.lib has an example: ## Suppose a package needs to call a DLL named 'fooEXT', ## where 'EXT' is the system-specific extension. Then you should use .First.lib <- function(lib, pkg) library.dynam("foo", pkg, lib) You cannot know that the package is in Sys.getenv("R_LIBS_USER") Note also that the .so file won't be in the path ..../src/... but in .../lib/... once you install the package in the recommended way using R CMD INSTALL. Really, please do read manual!!! > > and the package could installed, loaded and the lines with dyn.load worked. > It does not look like a pretty solution but works on my linux (I am > not sure if it works on my mac or windows). > > I am not sure if this is what you meant but as I have no clue what > .First.lib does or NAMESPACES means this is the best I come up with. So again time to read the manual and the help pages. Best, Uwe Ligges > Please correct me if I am wrong. > > Many thanks > > Ed > > > > On Fri, Aug 19, 2011 at 6:03 PM, Uwe > Ligges<lig...@statistik.tu-dortmund.de >> wrote: > >> >> >> On 19.08.2011 22:53, Eduardo Mendes wrote: >> >>> Dear R-users >>> >>> I am slowly migrating my mex files (MATLAB - Fortran and C) to R. >>> To get my own functions available on R section I have decided to >>> learn how to build >>> a >>> R package. I choose a simple example with a few Fortran and R >>> functions (wrapper). >>> >>> The fortran sources are located at src and the R functions at R (as >>> recommended). The building process went ok but R CMD check did not. >>> The error mgs was >>> >>> Error in dyn.load("fortran.so") : >>> unable to load shared object >>> '/home/eduardo/R_packages/**test.Rcheck/fortran.so': >>> >>> Although I can see that R cannot find the compiled fortran code I do not >>> know what to do. I believe it is something to do with the following >>> lines >>> in the R-wrapper file >>> >>> if (!is.loaded('calnpr')) >>> dyn.load("fortran.so") >>> >> >> >> 1. If the package is called calnpr, the shared library is also called >> that way. >> 2. you have to provide the path to the shared library. >> >> See ?.First.lib for how to do it in a package without NAMESPACE (and >> note that NAMESPACES are forced for the next R release). >> >> Best, >> Uwe Ligges >> >> >> How to add the path so that once the package is installed the >> compiled >>> fortran code can be found? >>> >>> Many thanks >>> >>> Cheers >>> >>> Ed >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________**________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/ >>> mailman/listinfo/r-help> PLEASE do read the posting guide >>> http://www.R-project.org/** >>> posting-guide.html<http://www.R-project.org/posting-guide.html> >>> and provide commented, minimal, self-contained, reproducible code. >>> >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.