[R] How to set default encoding for sourced files

Andrew Simmons @kw@|mmo @end|ng |rom gm@||@com
Wed Sep 21 21:40:29 CEST 2022


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 using 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 using 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list