Assume an R package (myPackage) that imports the R package RCircos via the DESCRIPTION file and the NAMESPACE file.
$ cat DESCRIPTION
Package: myPackage
Imports: RCircos (>= 1.2.0)
...
$ cat NAMESPACE
import(RCircos)
...
One of the perks of RCircos is that it defines a custom environment (called RCircos.Env) and reads/writes variables to this environment from various of its functions. For example, function RCircos.Initialize.Plot.Parameters reads and writes to this environment.
...
RCircosEnvironment <- NULL;
RCircosEnvironment <- get("RCircos.Env", envir = globalenv());
RCircosEnvironment[["RCircos.PlotPar"]] <- plot.param;
(This peculiar behavior has also been recognized by other R packages; see, for example, lines 247-249 of this package).
Unfortunately, it seems that the environment RCircos.Env is not recognized out of the box in myPackage when I simply import RCircos via the DESCRIPTION file and the NAMESPACE file.
So what can be done?
There seem to be two options of making the environment RCircos.Env accessible to functions like RCircos.Initialize.Plot.Parameters
. However, both of these options cause the CRAN check (R CMD check myPackage --as-cran
) to issue WARNINGs or NOTEs during the mandatory evaluation of myPackage prior to the submission to CRAN, thus preventing its acceptance on CRAN.
Option 1: I include the following line directly prior to the function demanding the object:
# my code here #
assign("RCircos.Env", RCircos::RCircos.Env, .GlobalEnv)
RCircos.Set.Core.Components(...)
# my code here #
However, the CRAN check highlights this line with a NOTE, thus preventing the acceptance of myPackage on CRAN.
* checking R code for possible problems ... NOTE
Found the following assignments to the global environment:
File ‘PACViR/R/visualizeWithRCircos.R’:
assign("RCircos.Env", RCircos::RCircos.Env, .GlobalEnv)
Option 2: I load the entire RCircos library prior to the function demanding the object:
# my code here #
library(RCircos)
RCircos.Set.Core.Components(...)
# my code here #
However, the CRAN check highlights this option with a WARNING, again preventing the acceptance of myPackage on CRAN.
* checking dependencies in R code ... WARNING
'library' or 'require' call not declared from: ‘RCircos’
'library' or 'require' call to ‘RCircos’ in package code.
Please use :: or requireNamespace() instead.
See section 'Suggested packages' in the 'Writing R Extensions' manual.
Surely, there must be an easy and CRAN-compatible way of making the environment RCircos.Env accessible to functions such as RCircos.Set.Core.Components
within myPackage! Can someone name and explain such a way?
@importFrom RCircos RCircos.Env
then@export
using {roxygen2} – HuonghupehRCircos.Env
in the global enviroment when usingRCircos
as a user?XGR
seems to just call functions likeRCircos.Set.Core.Components()
, never assigning anything to the global environment as far as I can see. – RichmondRCircos
as an import for myPackage in the DESCRIPTION file. Is that correct? – KluteRCircos::RCircos.Env
, and you can re-export it, as seasmith said. That's e.g. whatdplyr
does with the%>%
operator frommagrittr
. But that doesn't solve your CRAN issue that you aren't allowed to write to the global environment – Richmondassign("RCircos.Env", RCircos::RCircos.Env, .GlobalEnv)
. So I guess the question is why you need to have thatassign
. – Richmondassign
or equivalent to have the environment RCircos.Env recognized in myPackage, because simply importing RCircos via the DESCRIPTION file and the NAMESPACE file apparently doesn't transfer the environment. – Klute