Is local preferred to prevent *any* access to the internal environment
of the returned function?
How is it different than this?
myFunc <- function() {
notWarnedYet <- TRUE
function(x) {
if (notWarnedYet) {
warning("myFunc is funky")
notWarnedYet <<- FALSE #
> Is local preferred to prevent *any* access to the internal environment
> of the returned function?
You can gain access to the environment of the function by using
environment(myFunc), with either local() or your suggestion of
making a factory function and calling it.
> How is it different than
You could use local() to associate a state variable with your function:
myFunc <- local({
notWarnedYet <- TRUE
function(x) {
if (notWarnedYet) {
warning("myFunc is funky")
notWarnedYet <<- FALSE # note use of <<-
}
sqrt
Hi,
I'm writing a function that gives a warning in a certain scenario.
Reading this once per R session will be enough.
i.e. it's not necessary to be shown in subsequent function calls.
What's the best way to implement this?
Some package-specific option?
Where would I find good information on tha
4 matches
Mail list logo