Configure R to use utf-8 by default - r

To avoid problems when using R and RStudio, can R be configured to work with utf-8 by default? My system is windows 10 64 bit, R scripts are saved as ANSI, however when opening those same files with RStudio there are problems with the Latin characters, ñ, tildes, euro symbol €. I have to convert the files to change the character encoding, so that I can use them with RStudio.
From the R console:
> sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.5

In RStudio go to Tools bar, then click Global options (at the bottom):
See picture below: Click Code, then Saving -> you can set default text encoding

Related

opencv crashing R session?

I'm running some very simple code:
library(opencv)
ocv_video(ocv_face)
And the session immediately aborts.
Any ideas? (note: running R 4.0.2)
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] opencv_0.1
loaded via a namespace (and not attached):
[1] compiler_4.0.2 magrittr_1.5 tools_4.0.2 Rcpp_1.0.4.6
Solution
For anyone else who arrives here, the solution is to run the same code from terminal. That is press cmd + space to bring up spotlight search, type terminal to open terminal. Type R to open the R interpreter, and use that instead of RStudio.
Cause of the crash
The reason it works from terminal but no RStudio is because from terminal, a prompt will appear asking you to give opencv permission to use your webcam, but this prompt will not appear in RStudio (it causes the crash).

Synchronizing R system settings from Terminal, GUI and RStudio

My problem on my MacOS is that I can use R from GUI (aka console, downloaded from CRAN), Terminal or from RStudio but I cannot have them function in the same way.
Specific example is I can use rJava on Terminal and RStudio but not on GUI. Similar stuff happens for Rmarkdown pdf outputs. I usually get errors from GUI but everything is fine on Terminal or RStudio. How do I update R GUI settings to the same as Terminal's?
ps. For instance R CMD javareconf command handled the Terminal R but not R GUI.
edit: It is not actually something that requires a minimal working example but let's try library(rJava) after installing it.
R Called from Terminal (same with RStudio)
No problems.
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.5
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] C/UTF-8/C/C/C/C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.0
R GUI
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.5
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.0 tools_3.5.0
Some differences between Sys.getenv() are GUI has the following extra
LD_LIBRARY_PATH :#JAVA_LD#
DYLD_LIBRARY_PATH /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/lib/server
Brief update: I was able to correct Rmarkdown situation by using this link and reading help by writing ?Startup on R console. Changed the Renviron file on my R.home()/etc/. But still no rJava.
For R Markdown problem, I managed to handle it by adding a ~/.Renviron file and defining PATH parameter with the value I got from Terminal's Sys.getenv() parameters.
The only thing that worked for rJava for High Sierra is the following answer (changed the version to 3.5 though)
https://stackoverflow.com/a/47685001/3608936

Adding degree symbol in roxygen2

How to add degree symbol using roxygen2 for R documentation?
°C works in pdf, but it html, it is shown as °C.
Here is the session info.
R version 3.4.0 (2017-04-21)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=English_India.1252 LC_CTYPE=English_India.1252 LC_MONETARY=English_India.1252
[4] LC_NUMERIC=C LC_TIME=English_India.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0
To add any non-ASCII characters in R documentation using roxygen2, the encoding must be declared using the tag #encoding.
So when °C is used in the roxygen code, adding the tag #encoding UTF-8 will render it correctly for html as well as pdf.
This can be checked with
path <- "path to Rd file"
tools::checkRd(path)

Rterm.exe error in RStudio

I am using R 3.2.2 and RStudio 0.99.486 (latest version) under Windows 7 SP1 64 bit. I always get an error when I start RStudio:
the procedure entry point vsnprintf could not be
located in the dynamic link library R.dll
But I don't get any errors when I directly start R 3.2.2.
The R installed into C:/ProgramFiles/R/R-3.2.2/ (not the default path) and don't have other versions of R. RStudio is setup to use the installed R.
Except I get an error in RStudio, all my R codes can run in RGUI and RStudio.
Thanks for any suggestions to solve this annoying problem.
My session information
sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.2.2
> .libPaths()

In Windows 7x64R: set ghost script environment variable

What am I missing here, it works on another PC. From R Im trying to use Sys.setenv() to invoke ghost script. Then, normally I can use tools::find_gs_cmd() to check that it is set.
Heres the ghostscript exe:
> dir("C:/Program Files/gs/gs9.16/bin/")
[1] "gsdll64.dll" "gsdll64.lib" "gswin64.exe" "gswin64c.exe"
But when I try to set it I think it does NOT do it:
> Sys.setenv(R_GSCMD="C:/Program Files/gs/gs9.16/bin/gswin64c.exe")
> tools::find_gs_cmd("gswin64c.exe")
gswin64c.exe
""
If I use Sys.getenv() it is there on the list of environment variable all right, so Im a little unsure what is happening.
My system is:
> sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
[5] LC_TIME=Danish_Denmark.1252
attached base packages:
[1] tools stats graphics grDevices utils datasets methods base

Resources