[R] difference between script and a function....

Andrew Simmons @kw@|mmo @end|ng |rom gm@||@com
Sat Dec 24 15:48:12 CET 2022

1. The execution environment for a script is the global environment. Each R
script run from a shell will be given its own global environment. Each R
session has exactly one global environment, but you can have several active
R sessions.

2. Using return in a script instead of a function will throw an error

Error: no function to return from, jumping to top level

3. You can use print(), cat(), and writeLines() to write to the output. It
does not save your R objects before it exits the script. You could use
save() or save.image() to save your objects, or possibly saveRDS() if you
are only looking to save one object. You could also use source() if you
just want the objects from another script.

4. Will you have shared access to the objects in another R session? No,
objects are not shared, unless you've got something weird setup with
external pointers. Each session has it owns global environment.

5. Any of the doc pages for the functions I listed above would help, you
can also do


	[[alternative HTML version deleted]]

More information about the R-help mailing list