3 First steps
3.1 Interacting with R
The only meaningful way of interacting with R is by typing into the R console. At the most basic level, anything that we type at the command line will fall into one of two categories:
Assignments
x = 1 y <- 2
Expressions
1 + pi + sin(42)
## [1] 3.225071
The assignment type is obvious because either the The “<-” or “=” are used. Note that when we type expressions, R will return a result. In this case, the result of R evaluating 1 + pi + sin(42)
is 3.2250711
.
The standard R prompt is a “>” sign. When present, R is waiting for the next expression or assignment. If a line is not a complete R command, R will continue the next line with a “+”. For example, typing the fillowing with a “Return” after the second “+” will result in R giving back a “+” on the next line, a prompt to keep typing.
1 + pi +
sin(3.7)
## [1] 3.611757
3.2 Rules for Names in R
R allows users to assign names to objects such as variables, functions, and even dimensions of data. However, these names must follow a few rules.
- Names may contain any combination of letters, numbers, underscore, and “.”
- Names may not start with numbers, underscore.
- R names are case-sensitive.
Examples of valid R names include:
pi
x
camelCaps
my_stuff
MY_Stuff
this.is.the.name.of.the.man
ABC123
abc1234asdf
.hi
3.3 Resources for Getting Help
There is extensive built-in help and documentation within R.
If the name of the function or object on which help is sought is known, the following approaches with the name of the function or object will be helpful. For a concrete example, examine the help for the print
method.
help(print)
help('print')
?print
If the name of the function or object on which help is sought is not known, the following from within R will be helpful.
help.search('microarray')
RSiteSearch('microarray')
There are also tons of online resources that Google will include in searches if online searching feels more appropriate.
I strongly recommend using help(newfunction)
for all functions that are new or unfamiliar to you.