Objects in R Language: Secrets

The post is about objects in R Language. In R everything is an object. The commands run in a session can be saved or loaded in a file as history.

Loading Saved Work

Question 1: How can I retrieve (load) the saved work using the history function in R?
Answer: The loadhistory() function will load an “.Rhistory” file.

loadhistory("d:/file_name.Rhistory")

This function will load the file named “file_name.Rhistory” from D: drive.

The other way may be to access the “.Rhistory” file through the file menu. For this click File and then Load History. From the dialog box, browse the folder where you saved the “.Rhistory” file and click open to start working.

Script File in R

Question 2: How do I use a script of commands and functions saved in a text file?
Answer: The script of commands and functions saved in a text file (also called a script file) can be used to write the following command.

source("d:/file_name.txt")

The “file_name.txt” will load from D: drive.

Question 3: How do I get R to echo back the R commands and functions in a script file that I am sourcing into R? That is, the functions that I have written, I want to see these functions are being executed.
Answer: use echo=TRUE argument by using source() function

source("d:/file_name.txt", echo = T)

Question 4: How do I close the help file when working on a Macintosh operating system?
Answer: Typing just q will close the help file and bring you back to the R console.

Objects in R Language: Currently Available Objects

Question 5: How can I see a list of currently available objects in R?
Answer: Use the objects() or ls() functions to see the list of objects currently available

objects()
ls()
Objects in R Language

Remove Objects and Functions

Question 6: How do I remove/delete unwanted objects and functions?
Answer: The rm() function can be used to delete or remove the objects that are not required. The commands below will delete objects named object_name1 & object_name2 and functions named function_name1 & function_name2.

rm(object_name1, object_names2)
rm(function_name1, function_name2)

https://gmstat.com

https://itfeature.com

Leave a Reply

Discover more from R Language Frequently Asked Questions

Subscribe now to keep reading and get access to the full archive.

Continue reading