Noob trying to solve a NAMESPACE issue

package

#1

I set a goal to learn how to write R packages. As part of this goal I have been making silly little packages. The one I am currently working on makes quantile framed plots.

Things work okay --- I am sure there are many problems a trained eye would see that I don't --- but I have to load library(grid) before I can use the functions in my package. This is due to a function called grid::gList

I am assuming this is a NAMESPACE issue, but I have had difficulty fixing it. normally I would use gird::gList, but gList is in quotes in another function, so I am stumped.

The problem line is here


#2

Nice job, @alex628! I've been taking the same route, building tiny little ggplot2 extensions as a way to learn package development.

AFAIK there are two places—unfortunately similarly named—where you usually need to signal that you need another package's function. One is in the DESCRIPTION file, where you already have Imports: grid.

The other is in the NAMESPACE file. I see that your offending line is inside GeomQuantileFrame, which is decorated with a # @export comments. If you also add # @importFrom gridTree, roxygen2 should add that function to the NAMESPACE. You also shouldn't need the package-qualified version of the call, grid::gTree, since you also have grid listed in your DESCRIPTION file.

EDIT: I might be leading you stray with the theory here. I'd recommend having a close look at the linked section above, 'cause it really helps to untangle the relationship between NAMESPACE and DESCRIPTION, but I'm def not an expert on this :smiley:


#3

You don't have to quote functions passed to do.call. For example,

do.call(purrr::rbernoulli, list(10))
#>  [1]  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE

So you could write

ggplot2:::ggname("geom_quantileframe", grid::gTree(children = do.call(grid::gList, rugs)))

I'd generally advise avoiding messing with the NAMESPACE file, or if you must, do so through roxygen.


#4

Welcome to the fun-filled world of package development! It looks like you're off to a great start. You do a good job with making sure functions are preceded with grid::, and you have the grid package listed in your DESCRIPTION. What you need are roxygen2 tags in your function file above where you export your function:

#' @importFrom grid gList
#'
#' @export

Once you have those tags in there, you can run devtools:::document() and your NAMESPACE should be updated. This will mean you won't have to library(grid) in the future with your package.


#5

Thanks, I did not realize I did not have to quote functions passed to do.call


#6

Thanks to everyone's input I was able to fix the issue, commit, and push. Really appreciated the help :smile: