[R] Beginner’s Question

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Jun 12 10:39:29 CEST 2017

On Mon, Jun 12, 2017 at 2:39 AM, Neil Salkind <neiljsalkind at gmail.com> wrote:
> Please excuse the naive question but my first hour with RStudio, resulted in this…
>> data()
>> data(“women”)
> Error: unexpected input in "data(�”
> So,that did not work but
> without the quotes did.
> Would someone be so kind as to explain the function of quotes in RStudio? Thanks, Neil

First of all this is R, not RStudio. R is the language, the core, it
does all the computation. RStudio is just a pretty wrapper that lets
you click menus and arranges all your windows for you because it
thinks it knows how to arrange windows better than your operating
system. But I digress.

Quotes in R are used to define character strings. You can use single
or double quotes, but the exact same quote mark is used at the start
and finish. Unlike in proper books, R doesn't use "66" quotes at the
start and "99" quotes at the end of a string. Some word processors
will magically change standard plain quotes to super cute 66 and 99
quotes which seems to be how they may have sneaked into your RStudio

Now in R, if you just type a word it usually means the value of the
thing with that name. So there's a difference between:

 x = y


 x = "y"

In the first case, x is going to get the value of an object called y,
and if there is no object called y it will error. In the second case x
is going to get the character value "y", and there's no object called
y involved at all. But there are exceptions....

The library function is probably the first exception people come
across. You can type:


without using any quotes, and even though there's no object called
stats, you don't get an error. The code in the library function uses
special powers to look at what you typed rather than the value of an
object called stats that you passed to the function. This means that
although there is a package called ggplot2 on my system, this doesn't

 > thing="ggplot2"
 > library(thing)
 Error in library(thing) : there is no package called ‘thing’

It looks for a package called thing rather than one called ggplot2. Surprise!

You *can* pass a character string value to library, so both
library(ggplot2) and  library("ggplot2") both work the same.

The data function is another function that uses the same methods as
library to get what you asked for. So (once you get your quotes
straightened out) you can do:


or (double quotes):


or (single quotes):


Those of us who see this kind of behaviour as an impurity in a
language shudder when we think about it - names are names and strings
are strings - but others are grateful for saving two keystrokes every
time they type library(ggplot2).

> *********************************
> Whenever the people are well informed, they can be trusted with their own government.  ~ ~ ~Thomas Jefferson
> Neil J. Salkind
> (785) 841-0947
> neiljsalkind at gmail.com
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list