Foreign function call to a base package in R
1
0
Entering edit mode
ric.romoli • 0
@ricromoli-6990
Last seen 10.0 years ago
Italy

I'm writing a new R function that uses a modified version of the cor function (i.e. cor2), to do this I used the bare bone of the native cor function. In the original code is present a call to a C_cor function in the package stats. I try to run the cor2 function but I get the following error:

Error: object 'C_cor' not found.

I modified the call to the compiled function from

.Call(C_cor, x2, y2, 1L, method == 'kendall')

to

.Call(stats:::C_cor, x2, y2, 1L, method == 'kendall').

After that all works fine.

When I try the R CMD check command to verify the package I'm working to, I get:

* checking dependencies in R code ... NOTE
Unexported object imported by a ':::' call: ‘stats:::C_cor’
  See the note in ?`:::` about the use of this operator.
See the information on DESCRIPTION files in the chapter ‘Creating R
packages’ of the ‘Writing R Extensions’ manual.

and :

* checking foreign function calls ... WARNING
Foreign function call to a base package:
  .Call(stats:::C_cor, ...)
Packages should not make .C/.Call/.External/.Fortran calls to a base
package. They are not part of the API, for use only by R itself and
subject to change without notice.

I read the 'Writing Extension' manual but I've not been able to solve the problem. I also tried to find the C_cor funcion in the stats package (from a fresh R download) as suggested by Uwe Ligge... I found the cov.c function  from within the cor function is called... I think... I tried to copy the cov.c file and compile it but I get several errors:

:$ R CMD SHLIB cov.c
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -O2 -pipe -g  -c cov.c -o cov.o
cov.c:31:18: fatal error: Defn.h: No such file or directory
compilation terminated.
make: *** [cov.o] Error 1

I copied the Defn.h file too but the error persist. I'm not expert in c and I have not the idea how to overcome this problem.

Do you have any suggestion? 

Indeed how can I overcome the NOTE and the WARNING from the R CMD check?

All the best

software error CMD check • 1.9k views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 3 months ago
United States

It's more appropriate to ask questions about Bioconductor package development on the Bioc-devel mailing list, but I know you've already asked on StackOverflow, so...

It would help to know a little more about what you are doing. From cor it looks like the code path to the .C call just checks that the arguments are valid, then calls the C function. So shouldn't you be able to just use cor() and put your code before or after it?

mycor <- function(x, y=NULL, ...) {
    ## before things
    ans <- cor(x, y, ..., method="kendall")
    ## after things
    ans
}

I don't think it would be a good idea to copy C code (unnecessary code duplication) or to use the naked .C call (the authors of the stats package have no obligation to maintain compatibility with your invocation.)

ADD COMMENT

Login before adding your answer.

Traffic: 597 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6