rpackageconflictcompiled

R package building: importing functions with identical names


I am building a R package importing two functions entitled "rngseed" from two different R packages (entitled cat and mix). Unfortunately, such a package cannot be deposited on the CRAN because of the conflict with the names of imported functions. My question is how to solve this problem.

My idea was to copy one of both (the one from the R pacakge cat) and include it in my R folder under another name. The function is as follows:

function (seed) 
{
    seed <- as.integer(seed)
    if (seed <= 0) 
        stop("Seed must be a positive integer")
    tmp <- .Fortran("rngs", seed, PACKAGE = "cat")
    invisible()
}

I understand it is based on a Fortran subroutine. I am not very comfortable with including Fortran or C functions in my package. After several readings, I essentially tried to modify the NAMESPACE file by adding a line like useDynLib(cat,rngs), but I seems not relevant since when installing the package on my laptop, I obtain an error "the DLL 'cat' is not found".

I hope my post is clear enough. Thank you very much for your help to solve my issue, using a copy of one of both functions or in another manner.

Best,

Vincent


Solution

  • I think you are trying to do this at too low of a level. It works for me if I declare cat and mix as imports, and in my NAMESPACE file I have this:

    importFrom(cat, catseed = rngseed)
    importFrom(mix, mixseed = rngseed)
    

    The fact that those functions call Fortran functions internally doesn't matter if I'm only going to call them as R functions.