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.

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


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.

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 by writing the following command.


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

Script File in R

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

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 in R Language

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)



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