Thanks. The --encoding option indeed makes it all work. Rscript --help does not show the --encoding option in the list of options.

And yes, you are right. I was using R 4.1.2 when I first wrote to the list. I was experiencing a technical issue with R 4.2.1 which was preventing me from switching over to it but I have a satisfactory solution to the problem now and have just moved to R 4.2.1. It seems that, on Windows at least, R 4.2.1 does indeed use utf-8 as its native encoding. I didn't realise this. At any rate, it looks like merely upgrading solves my encoding concerns without the need to set options or specify the encoding with Rscript. Very nice and kudos to the R developers for taking the leap!

Thanks everyone for your help.

Cheers,
Andrew.


On 21/09/2022 16:40, Andrew Simmons wrote:
If you're running it from Rscript, you'll have to specify the encoding like this:

Rscript --encoding UTF-8 file

If you're using R for Windows, I'm surprised this issue would come up since R 4.2.0 added support for UTF-8. At least on my own Windows machine, I can run exactly what you wrote and not have any issues. Are you using an older version of R?


On Wed., Sep. 21, 2022, 14:20 Andrew Hart via R-help, <r-help@r-project.org <mailto:r-help@r-project.org>> wrote:

    On 21/09/2022 11:46, Bert Gunter wrote:
     > ?options
     >
     > options(encoding = "utf-8")
     > in a startup file or function should presumably do it. See ?Startup
     >
     > Bert

    Thanks everyone. Setting encoding in options in Rprofile.site has taken
    care of it.

    Curiously, it doesn't seem to solve the whole problem for Rscript
    though. I checked that Rscript is indeed picking up the default
    encoding
    from options, but it's complaining about seeing an unexpected input in
    dat$lĂ­nea <- ....
    immediately following the l when I run
    Rscript myfile.R.
    So, it would appear that Rscript is not using source to read in the R
    script. Mind you, if I do
    Rscript -e source('myfile.R')
    it works properly just like in Rgui.

    Once again, Thanks heaps.

    Cheers,
    Andrew.

    ______________________________________________
    R-help@r-project.org <mailto:R-help@r-project.org> mailing list --
    To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    <https://stat.ethz.ch/mailman/listinfo/r-help>
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    <http://www.R-project.org/posting-guide.html>
    and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@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.

Reply via email to