Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

Question

Is rm(list=ls()) at the beginning of a R job that's run in batch useful or otherwise a best practice?

Answer

Yes, it can be useful to start off your batch script with the command 'rm(list=ls())' just to make sure that you have a clean R environment before submitting the batch job. For example, you may have users that have their own .Rprofile files with a sequence of commands in them that create some R objects on startup of R. In that case it may be useful, to erase any existing R objects before running the R code for the batch job.

For example, here is pseudocode to do this:

x <- ls() 
if (x is not empty) { 
rm(list=ls() 
}

Yes, you can certainly run code like this after startup to remove existing R objects from the user workspace. 

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×