R is an interpreter language. It reads each complete instruction and executes it. I emphasize on complete, because while doing any of the tutorial, if you run into tantrums from R please check if any of the categories explained below.
Errors introduced because of incorrect command syntax.
Did I miss any brackets i.e. (),[],{}
or quotes "",'',
or a ,
? For fun, try to run the command below by omitting any of your favorite punctuation:
a <- {c("x","y",'z')}
For many more examples on syntax and R
style guide, please refer to this helpful link
Did I make any spelling mistakes in the name of the objects/functions/file names? The example below should also give you an insight into the complications that might arise if the object/function names are not simple.
chiaroscurist <- 750
brobdingnagian <- 4929
chiaroscurist+brobdingnagian
## [1] 5679
Errors introduced because of flawed logic Is my command complete i.e. did I miss some input value or did I provide an empty data set?
x <- 2 # change 2 to "2" and see what happens
y <- 4929
x+y
## [1] 4931
Is the sequence of instructions correct?
x <- 2 # change 2 to "2" and see what happens
y <- 4929
x+y
## [1] 4931
We might notice that sometimes the numbers we are trying to compute do not make any sense. Before we blame R
, lets check if we are asking R
to do the math in the right order:
\(f(x)=1/(a+b)\)
a <- 90
b <- 10
1/(90-10)
## [1] 0.0125
Bonus points if you can point out what did I wrong here:
a <- 90
b <- 10
1/90+10
## [1] 10.01111
Introduction to R by Dr. Sarath Chandra Dantu
This course material is available under a Creative Commons BY-SA license (CC BY-SA) version 4.0