Skip to content
Prev 6013 / 12125 Next

[R-pkg-devel] Use of `:::` in a package for code run in a parallel cluster

Thank you all for the discussion and suggestions.

so making a package function baz available makes all functions in the
Thanks, Martin. I completely missed that the parallel package serializes
the entire environment of the function, including the package namespace and
so `:::` is indeed unnecessary in my use case. I probably experimented in
the global environment first and extrapolated the observed behaviour to the
package. Sorry for annoying everyone with this.

I also have another use of `:::` for which I am not sure if it's considered
disallowed use of `:::`, so I'm throwing it out there for feedback.
I have one internal function which checks a long list of common arguments
to several other functions, similar to
internal_check_args <- function (sd = 2, type = c("bootstrap",
"theoretical"), ...) {
  # check arguments for valid ranges, etc.
  return(list(sd = sd, type = match.arg(type))
}

And several functions which use the internal function for argument checking
and such, similar to
exported_foo <- function (x, sd = 2, type = c("bootstrap", "theoretical")) {
  args_call <- match.call()
  args_call[[1]] <- quote(mypackage:::internal_check_args)
  args <- eval.parent(args_call)
}

exported_foo_cv <- function (x, cv_folds = 3, ...) {
  args_call <- match.call(expand.dots = TRUE)
  args_call[[1]] <- quote(mypackage:::internal_check_args)
  args <- eval.parent(args_call)
}

This is modelled after what, e.g., `lm()` does with `model.frame()`, only
that `internal_check_args()` is not exported, hence I use `:::`. There are
other solutions for this type of use of `:::` (probably some considered
cleaner) but again without guidelines on when `:::` is acceptable it's
difficult for package maintainers to know when to use/not use it. From all
the discussions it seems that there is absolutely no acceptable use of
`:::` and work-arounds are always the better alternative.

In light of the other interesting points brought up by discussants, I also
want to honor their time and reply here.

You may argue that you prefer pkg:::foo for some reason:  to which I'd
I am sorry it came across rude when I tried to solicit arguments for why
the use of `:::` is considered "bad practice", while work-arounds are
considered to be okay. I wouldn't force CRAN to handle my case specially; I
rather wanted to challenge the general "attitude" towards the use of `:::`.
I am sure there is a need to discourage the use of `:::` in packages as
CRAN volunteers probably have seen hundreds of cases where `:::` was abused
(such as mine, as Martin Morgan pointed out).

you can use
That would be a work-around I would have used if necessary. But my general
question remains: why should I reinvent the wheel when R already comes with
`:::`? The only advantage of all the work-arounds I've seen would be to
trick R CMD check that the code is okay, when in fact the same "bad
practice" is practiced.

Best,
David

On Sun, Sep 13, 2020 at 3:04 PM Martin Morgan <mtmorgan.bioc at gmail.com>
wrote:

  
  
Message-ID: <CAGmyFCEUtz-VnaMCYRKk=01qWGT3pADgacQ-mmYKTmUmW_E6fw@mail.gmail.com>
In-Reply-To: <BL0PR04MB660968418CA6161F5D51234CF9220@BL0PR04MB6609.namprd04.prod.outlook.com>

Thread (17 messages)