Using " instead of '

I've been using RStudio for a while now but still can't fix the issue of single quote '. In Oracle R Enterprise (ORE), my R script works fine with double quote "text" similar to what is advocated for R coding but it's not accepted in my RStudio. What's worse is that RStudio doesn't even accept ' created in MS Word or Notepad. The ' has to be that which is manually entered in RStudio. I've done web search but haven't found anyone encountering a similar problem and have looked through Global Options but can't find a way to fix this. Any help is appreciated.

Hi, and welcome!

It may be a character code default issue

paste("This is text cut and pasted from a plain text editor on a Mac that includes the single quote mark, '")
#> [1] "This is text cut and pasted from a plain text editor on a Mac that includes the single quote mark, '"

Created on 2019-10-25 by the reprex package (v0.3.0)

What's your system, and can you provide a reproducible example, called a reprex?

Thanks Richard for the quick response. The result is same as yours. I’m using RStudio with R 3.3.0 on Win10.

This is an e.g. of the error

applicant <- subset(applicant, rated != ”Yes”) # Keep only applicants not yet rated
Error: unexpected input in "applicant <- subset(applicant, rated != ”"

If you look closely the culprit is the curly quotes. See the end of the error message: ”"

It's been too long since I've had to use WIN to suggest a way to turn them off, but I'm sure there must be a way.

These are 3 entries with the last using RStudio keystroke

applicant <- subset(applicant, rated != ”Yes”) # Keep only applicants not yet rated
Error: unexpected input in "applicant <- subset(applicant, rated != ”"
applicant <- subset(applicant, rated != β€˜Yes’) # Keep only applicants not yet rated
Error: unexpected input in "applicant <- subset(applicant, rated != β€˜"
applicant <- subset(applicant, RATED != 'Yes') # Keep only applicants not yet rated
reprex()

Even the single quote ' created with Notepad can't be accepted. This is especially frustrating as " works fine in ORE and I've to keep changing quotes manually just to test the codes on RStudio.

1 Like

I feel your pain. I wish I knew what you had to do to insert uncurly single and double quotes into RStudio.

All l've found is a kludge

Thanks but that'll be tedious.
Is there a way to get RStudio to accept " instead of ' for text?

RStudio will accept either ' or " but not β€˜,’, β€œ or ”, AFAIK.

?Quote says that ' and " are interchangeable but it simply isn't the case in my RStudio.

Single and double straight quotes are interchangeable in pairs with each other, but both single and double curly quotes are not interchangeable with their straight counterparts:

' = ", ' \ne β€˜ & '\ne ’, " \ne β€œ & " \ne ”

I suspect there is an encoding issue involved - your quotation marks may not be what they seem.

What does your sessionInfo() say about your locale?

I once had a similar issue that I resolved by adjusting my .Rprofile file (meaning it was a R issue, not an RStudio issue).

2 Likes

Thanks Jindra. This is the locale info
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252

That is a pity of sorts, for US English at 1252 is a sensible default when UTF-8 is unavailable (there might be an issue with curly, aka "smart" quotation marks, but in principle codepage 1252 should not throw a problem for ASCI characters).

You might consider re-setting the locale to system default just in case by running
Sys.setlocale(category = "LC_ALL", locale = "")
but your issue seems different from mine after all :frowning:

1 Like

RStudio was installed without any modification so all settings should've been default. The results remain unchanged even after I replaced smart quotes with straight quotes. You may be right that it has to do with the R version rather than RStudio as I tried using Tinn-R and encountered the same problem. I'm using Oracle R Distribution 3.3.0 for compatibility which may be causing this. Thanks for the insight.

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.