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
>
>>data(women)
>
> 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
session.
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
and
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:
library(stats)
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
work:
> 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:
data(women)
or (double quotes):
data("women")
or (single quotes):
data('women')
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.