Search code examples
rnamespacespackagedevtoolsroxygen2

How to prevent importFrom statements from autodeletion from NAMESPACE file?


My NAMESPACE file is:

# Generated by roxygen2 (4.0.1): do not edit by hand
export(ARorderG)
export(VOBoegmc)
export(conddiffG)
................
export(sablon)

Upon trying to check the package via:

devtools::check("C:/Users/erdogan/Documents/Revolution/causfinder")

I received lots of errors like that:

conddiffG: *no visible global function definition for* 'b.star'. 

What I have already tried till now: I added the following importfrom to NAMESPACE file manually:

importFrom(np, b.star)

I did these for all the "...no visible global function definition for..." errors. Then once more I triggered:

devtools::check("C:/Users/erdogan/Documents/Revolution/causfinder")

Unfortunately, all the importFrom statements were automatically deleted from NAMESPACE file. I read that this is due to re-creation of NAMESPACE file from roxygen2.

I needed importFrom statements for successful check of package to send CRAN, but roxygen2 auto-deletes these importFrom statements and left only export statements.

How to prevent deletion of importFrom statements via using roxygen2?

Any help is greatly appreciated in advance.


Solution

  • roxygen2 automatically updates the content of NAMESPACE file. Hence, in order to prevent importFrom statements in NAMESPACE file from auto-deletion, these statements must be brought to the NAMESPACE file from the .R files of the functions of the package; not to be written manually to NAMESPACE file. For the sake of arguement, let the function conddiffG use some function b.star of the package np. Then, in conddiffG.R of R folder of the package, we must write the following just before #' @export line:

    #’ @importFrom np b.star
    

    This will create importFrom(np,b.star) in NAMESPACE file automatically during the later processes (roxygenize, build, install, library, devtools::check("C:/Users/erdogan/Documents/Revolution/thePacketContainingconddiffG")...).