[R] adding FORTRAN code to a package

Ray Brownrigg Ray.Brownrigg at ecs.vuw.ac.nz
Tue Aug 3 22:58:27 CEST 2010


On Wed, 04 Aug 2010, Erin Hodgess wrote:
> Thank you!
>
> Now, here is the code for the FORTRAN subroutine:
>       subroutine cov1(n1,na,x,z,yy,ac)
>       integer n1,na
>       real x(n1),ac(na+1),z,yy
>       do 5 j=1,(na+1)
>          do 10 i=1,(n1-j)
>             if(j.eq.1)ac(j)=yy
>                if(j.ne.1)ac(j)=ac(j)+(x(i)-z)*(x(i+j-1)-z)
>
>  10            continue
>  5             continue
>       do 15 j=1,(na+1)
>          ac(j)=ac(j)/(n1-1)
>  15      continue
>          end
>
> Here is the Rcmd stuff:
> c:\R\R-2.11.1\bin>Rcmd check RcmdrPlugin.push
> Rcmd check RcmdrPlugin.push
> * checking for working pdflatex ... OK
> * using log directory 'c:/R/R-2.11.1/bin/RcmdrPlugin.push.Rcheck'
> * using R version 2.11.1 (2010-05-31)
> * using session charset: ISO8859-1
> * checking for file 'RcmdrPlugin.push/DESCRIPTION' ... OK
> * checking extension type ... Package
> * this is package 'RcmdrPlugin.push' version '0.1.0'
> * checking package dependencies ... OK
> * checking if this is a source package ... OK
> * checking for executable files ... OK
> * checking whether package 'RcmdrPlugin.push' can be installed ... OK
> * checking package directory ... OK
> * checking for portable file names ... OK
> * checking DESCRIPTION meta-information ... OK
> * checking top-level files ... OK
> * checking index information ... OK
> * checking package subdirectories ... OK
> * checking R files for non-ASCII characters ... OK
> * checking R files for syntax errors ... OK
> * checking whether the package can be loaded ... OK
> * checking whether the package can be loaded with stated dependencies ...
> OK * checking whether the package can be unloaded cleanly ... OK
> * checking for unstated dependencies in R code ... OK
> * checking S3 generic/method consistency ... OK
> * checking replacement functions ... OK
> * checking foreign function calls ... OK
> * checking R code for possible problems ... NOTE
> acfMod: no visible binding for global variable 'top'
: a whole lot more removed
> tsConv: no visible binding for global variable 'buttonsFrame'
> * checking Rd files ... OK
> * checking Rd metadata ... OK
> * checking Rd cross-references ... OK
> * checking for missing documentation entries ... WARNING
> Undocumented code objects:
>   bigfore bigfore1 eplot3 ewMod forearMod illSelect subewMod
> All user-level objects in a package should have documentation entries.
> See the chapter 'Writing R documentation files' in manual 'Writing R
> Extensions'.
> * checking for code/documentation mismatches ... OK
> * checking Rd \usage sections ... OK
> * checking Rd contents ... OK
> * checking data for non-ASCII characters ... OK
> * checking line endings in C/C++/Fortran sources/headers ... WARNING
> Found the following sources/headers with CR or CRLF line endings:
>   src/cov1.f
> Some Unix compilers require LF line endings.
> * checking line endings in Makefiles ... OK
> * checking for portable use of $BLAS_LIBS ... OK
> * checking examples ... NONE
> * checking PDF version of manual ... OK
>
> WARNING: There were 2 warnings, see
>   c:/R/R-2.11.1/bin/RcmdrPlugin.push.Rcheck/00check.log
> for details
>
>
> c:\R\R-2.11.1\bin>Rcmd build RcmdrPlugin.push
> Rcmd build RcmdrPlugin.push
> * checking for file 'RcmdrPlugin.push/DESCRIPTION' ... OK
> * preparing 'RcmdrPlugin.push':
> * checking DESCRIPTION meta-information ... OK
> * cleaning src
> * checking whether 'INDEX' is up-to-date ... NO
> * use '--force' to overwrite the existing 'INDEX'
> * removing junk files
> * checking for LF line-endings in source and make files
>     file 'RcmdrPlugin.push/src/cov1.f' had non-LF line endings
> * checking for empty or unneeded directories
> * building 'RcmdrPlugin.push_0.1.0.tar.gz'
>
>
> c:\R\R-2.11.1\bin>Rcmd INSTALL RcmdrPlugin.push_0.1.0.tar.gz
> Rcmd INSTALL RcmdrPlugin.push_0.1.0.tar.gz
> * installing to library 'c:/R/R-2.11.1/library'
> * installing *source* package 'RcmdrPlugin.push' ...
> ** libs
>   making DLL ...
> gfortran     -O3  -c cov1.f -o cov1.o
> gcc -shared -s -static-libgcc -o RcmdrPlugin.push.dll tmp.def cov1.o
> -lgfortran -Lc:/R/R-2.11.1/bin -lR
> installing to c:/R/R-2.11.1/library/RcmdrPlugin.push/libs
>   ... done
> ** R
> ** data
> ** inst
> ** preparing package for lazy loading
> Loading required package: tcltk
> Loading Tcl/Tk interface ... done
> Loading required package: car
> Loading required package: MASS
> Loading required package: nnet
> Loading required package: leaps
> Loading required package: survival
> Loading required package: splines
> The Commander GUI is launched only in interactive sessions
>
> Attaching package: 'Rcmdr'
>
> The following object(s) are masked from 'package:tcltk':
>
>     tclvalue
>
> Loading required package: quadprog
> Loading required package: zoo
> Package 'qcc', version 2.0.1
> Type 'citation("qcc")' for citing this R package in publications.
>
> Attaching package: 'qcc'
>
> The following object(s) are masked from 'package:TeachingDemos':
>
>     limits.g, sd.g, stats.g
>
> Loading required package: lattice
> Loading required package: yaImpute
> stl2 1.0 loaded
> ** help
> *** installing help indices
> ** building package indices ...
> ** testing if installed package can be loaded
>
> * DONE (RcmdrPlugin.push)
>
> c:\R\R-2.11.1\bin>
>
> But here is what happens when I try to run:
> > bigfore1(x=x.TotalILI.d$zoo)
>
> begin
> Error in .Fortran("cov1.o", n1 = as.integer(n1), na = as.integer(na),  :
>   Fortran symbol name "cov1.o" not in DLL for package "RcmdrPlugin.push"
>
>
> What am I missing, please?

The FORTRAN symbol you have defined is cov1, but you are trying to use cov1.o, contrary to 
what Uwe suggested.

You have shown us the FORTRAN code, but you haven't shown the R code that uses it, so we 
don't have a reproducible example.

HTH,
Ray Brownrigg

> Should I have a statement in the .First.lib section, please?
>
> Thanks,
> Erin
>
> 2010/8/3 Uwe Ligges <ligges at statistik.tu-dortmund.de>:
> > I assume you will need
> >
> > .Fortran("cov1", ......, PACKAGE="RcmdrPlugin.push")
> >
> > if the fortran code is in your package.
> >
> > Best,
> > Uwe Ligges



More information about the R-help mailing list