2ton21
2ton21

Reputation: 199

R encoding unable to save symbol

I am working with an R script using RStudio (R version 2.15.3 on a PC [for various reasons I can't use a more updated version or R]) and am having trouble saving a script that has the parts per thousand symbol in it (‰). I can’t share my actual data but I have attached a simple example below:

library(ggplot2)
# Gen some random data
a <- data.frame(replicate(2,sample(1:10,500,rep=TRUE)))

# Plot with expressions for axes labels
basic <- ggplot(data = a, aes(X1, X2))+
geom_point()+
labs(list(colour="Catch Region", x=expression(paste(delta, ""^"13","C ","(‰)")), 
        y=expression(paste(delta, ""^"15","N ","(‰)"))))

basic

The graphed data in this example is nonsense but regardless it illustrates my point, as you can see my graph includes labels which have the ‰ symbol in them. Upon saving this script with RStudio I get the warring message:

Not all of the characters in C:/… could be encoded using ISO8859-1. To save using a different encoding, choose "File | Save with Encoding..." from the main menu.

RStudio has 12 different encoding types and I have tried them all, each either gives no warring upon saving but when the script is closed and reopened the ‰ symbol is gone, or gives the same warring as above with the following reload of the script producing nonsense characters instead of the ‰ symbol.

To date I have just been going through and changing the symbol back to ‰ each time I need to reopen the script, but it’s becoming a pain as my script library grows to have to do this for each one I open. Any help would be much appreciated.

Also, I realize there are a few other question on stackoverflow which deal with encoding issues but nothing I have found so far helps me with this specific issue.

Upvotes: 10

Views: 21337

Answers (1)

gagolews
gagolews

Reputation: 13066

Use "File -> Save with encoding -> UTF-8". Unicode is a "superset" of all the encodings, thus it handles all the code points you can imagine. Moreover, R also is Unicode-aware.

Upvotes: 22

Related Questions