Let's say I've written an R script which uses some variables. When I run it, those variables clutter the global R environment. To prevent this, how do I limit the scope of variables used in a script to that script only? Note: I know that one way is to use functions, are there any other ways?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
Just use the
local=TRUE
argument tosource
and evaluatesource
somewhere other than your global environment. Here are a few ways to do that (assuming you don't want to be able to access the variables in the script).foo.R
just containsprint(x <- 1:10)
.sys.source
is probably the most straight-forward solution.You can also evaluate the file in an attached environment, in case you want to access the variables. See the examples in
?sys.source
for how to do this.You can use the
local
function.