publicEval | R Documentation |
publicEval
creates an environment hierarchy consisting of
public, self, and private environments. The expression expr
is
evaluated within these nested environments, allowing for controlled
variable scope and encapsulation.
publicEval(expr, parentEnv = parent.frame(), name = NULL)
expr |
An expression to evaluate within the constructed environment hierarchy. |
parentEnv |
The parent environment for the new 'public' environment. Default is the parent frame. |
name |
Optional name attribute to set for the public environment. |
Returns an invisible reference to the public environment.
Public: Variables in this environment are externally accessible.
Self: Inherits from Public and also contains Private and Public as children.
Private: Variables are encapsulated and are not externally accessible.
publicEnv <- publicEval({
private$hidden_var <- "I am hidden"
public_var <- "I am public"
}, parentEnv = parent.frame(), name = "MyEnvironment")
print(exists("public_var", envir = publicEnv)) # Should return TRUE
print(exists("hidden_var", envir = publicEnv)) # Should return FALSE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.