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

akshay kulkarni @k@h@y_e4 @end|ng |rom hotm@||@com
Sat Dec 24 15:54:52 CET 2022


Dear Simmons,
                            Thanks a lot. One more question:


  1.  If there is  some error in the script, the error will be output to the stdout? Or to the file that it creates for saving the output of the script?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI
________________________________
From: Andrew Simmons <akwsimmo using gmail.com>
Sent: Saturday, December 24, 2022 8:18 PM
To: akshay kulkarni <akshay_e4 using hotmail.com>
Cc: R help Mailing list <r-help using r-project.org>
Subject: Re: [R] difference between script and a function....

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

?utils::Rscript

	[[alternative HTML version deleted]]



More information about the R-help mailing list