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 <akwsi...@gmail.com>
Sent: Saturday, December 24, 2022 8:18 PM
To: akshay kulkarni <akshay...@hotmail.com>
Cc: R help Mailing list <r-help@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]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to