Category «R Basics»

FAQ about R basic

R Basics

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

> loadhistory(“d:/file_name.Rhistory”)

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

The other way may be to access .Rhistory file through the file menu. For this click File and then Load history. From the dialog box appeared  browse to 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 script file) can be used by writing 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.

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()

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. 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)

R FAQs: Getting Help in R

Question: How one can get help about different command in R Language?
Answer: There are many ways to get help about different command (functions). R has built-in help facility which is similar to man facility in Unix. For beginners of R language, help() function or ? can be used to get help about different commands of R language.

Questions: Provide some examples about getting help?
Answer: To get more information on any specific R command (function), for example for getting help about solve(), lm(), plot() etc, write the following commands at R prompt:

> help(solve)
> help(lm)
> help(plot)

Question: Can one get help for special symbols, characters in R Language?
Answer: Yes one can get help for special characters. For example;

> help(“[[“)
> help(“[“)
> help(“^”)
> help(“$”)
> help(“%%”)

Question: What help.start() does?
Answer: The help.start() will launch a web browser that allows the help pages to browsed with hyperlinks. It can be a better way to get help about different functions.

Question: There is help.search() command. What for purpose it is?
Answer: The help.search() command allows searching for help in various ways. To get what help.search() functions does, write this command at R prompt;

> help(help.search)

Question: Provide some details about help.search() function and also illustrate it by providing some examples?
Answer: The help.search() allows for searching the help system for documentation matching a given character string in the (file) name, alias, title, concept or keyword entries (or any combination thereof), using either fuzzy matching or regular expression matching. Names and titles of the matched help entries are displayed nicely formatted. The examples are:

> help.search(“linear”)
> help.search(“linear models”)
> help.search(“print”)
> help.search(“cat”)

Question: How ? can be used to get help in R language?
Answer: The ? mark can be used to get help in Windows version of R Language. For example;

> ?print
> ?help
> ?”[[“
> ?methods
> ?lm

For further detials, follow the link Getting Help in R Language

R FAQs: Saving and Loading R workspace

Question: Can I save my work in R Language?
Answer: R language facilitates to save ones R work.

Question: How to save work done in R?
Answer: All of the objects and functions that are created (you R workspace) can be saved in a file .RData by using the save() function or the save.image() function. It is important that when saving R work in a file, remember to include the .RData extension.

> save(file=”d:/filename.RData”)
> save.image(“d:/filename.RData”)

Question: Is there alternative to save workspace in R?
Answer: Yes! You can also save work space using file menu. For this, click File menu and then click save workspace. You will see the dialog box, browse to the folder where you want to save the file and provide the file name of your own choice.

Question: How one can access the saved work, while work is saved using save.image() function?
Answer: The load() function can be used to load a .RData file.

> load (“d:/filename.RData”)

Question: Is there any other alternative to load workspace in R?
Answer: The .RData files can be accessed through the file menu. To access file click File and then load workspace. A dialog box will appear, browse to the folder where you saved the .RData file and click open.

Question: How do one can save all the commands that are used in an R session?
Answer: Saving R commands used in an R session means you want to save history of your R session in an .Rhistory file by using the history() function. It is important to include the .Rhistory extension when saving the file at different path.

> history(“d:/filename.Rhistory”)

Question: Can commands in R session be saved through File menu?
Answer: Yes command in R session be saved through file menu. For this click File and then save history. A dialog box will appear, browse to the folder where you want to save the file (that will contain R commands in a session) and provide the file name of your own choice.

FAQs about R

Question: Why R language is named as R?
Answer: The name of R language is based on the first letters of its authors (Robert Gentleman and Ross Ihaka).

Question: What is the R Foundation?
Answer: The R foundation is a non-profit organization working in the public interest, founded by the members of the R Core Team. This foundation provides support for the R project and other innovations in statistical computing, provides reference point for individual, institutions or commercial enterprises whom want to support or interact with the R development community. R foundation also holds and administer the copyright of R language software and its documentation. For more information about R foundation follow the link https://www.R-project.org/foundation

Question:What is R-Forge?
Answer: R-Forge provides a central platform for the development of R packages, R-related softwares etc. It is based on GForge that offers easy access to the best in SVN, daily built and checked R packages, mailing lists, bug tracking, message board or forum, web-site hosting, permanent file archival, full backups and total web-based administration. For more information see

  • The R-Forge web page
  • Stefan Theußl and Achim Zeileis (2009), “Collaborative software development using R-Forge”, The R Journal, 1(1), 9-14.

Question: What mailing lists exist for R language?
Answer: There are four mailing lists devoted to R language

  • R-announce: A moderated mailing list for major announcements about the R development and the availability of new R code.
  • R-packages: A moderated mailing list for announcement on the availability of new or further enhanced contributed packages.
  • R-help: The main R mailing list for discussion and problems and solution using R, announcements about the development of R and the availability of new R code. R-help is intended to people who want to use R to solve problems.
  • R-devel: A mailing list for questions and discussions about code development in R language.

Question: What documentation exists for R language?
Answer: For most of the R function and variables in R online documentation exists and this documentation can be printed on screen by typing help(name) or ?name at the R prompt, where name is the name of the topic for which help is required. The R documentation can also be made available in PDF and HTML formats and as a hardcopy via LaTeX. Up-to-date HTML version of R documentation is always available for web browsers at http://stat.ethz.ch/R-manual.Lot of R books and manuals are also available as R documentation.
How to get help in R follow the link Getting Help in R Language.

 

R Basic FAQs

Question: How to start (Run) R Language in Windows Operating System?
Answer: In Microsoft Windows, during installation the R installer will have created a Start menu item and an icon for R on your system’s desktop. Double click R icon from desktop or from start menu list to Run R program. For windows 7, 8 or 10, you can use search term like “R x64 3.2.1” (64 bit version) or “R i386 3.2.1” (32 bit version). R GUI will launch.

Question: How R can be used as calculator.
Answer: Starting R will open the console where user can type commands. To use R as calculator one have to enter the arithmetical expression after > prompt. For example

> 5 + 4
> sqrt(37)
> 2*4^2+17*4-3

Question: How to Quit R session?
Answer: In R console on R command prompt just type

> q( )

Question: What is q()?
Answer: The q() is a function that is used to tell R to quit. When q() is entered in R console and press Enter key, you will be asked whether to save an image of the current workspace or not or to cancel. Note that only typing q tells R to show the content of this function. The action of this function is to quit R.

Question: What is workspace in R?
Answer: The workspace in R is an image that contains a record of the computations one have done and it may contain some saved results.

Question: How to record work in R?
Answer: Rather than saving the workspace, one can record all the commands that one have entered in R console. Recording work in R, the R workspace can be reproduced. The easiest way is to enter the commands in R’s script editor available in the File menu of R GUI.

Question: What is R Script Editor?
Answer: R script editor is a place where one can enter commands. Commands can be executed by highlighting them and hitting CTRL+R (mean RUN). At the end of a R session one can save the final script for a permanent record of one’s work. A text editor such as Notepad can also be used for this purpose.
Note that in R console only one command can be entered at a time because after pressing Enter key the R command executed immediately.

 

%d bloggers like this: