axis labels are not plotted in English - r

R doesn't plot automatically the axis labels in English (for example Months are in French).
I use (if the information is useful...):
windows (and I have already changed "language = en" in .../Programs/R/etc/Rconsole to make R speaking English)
RStudio
ggplot2
I know that I am not the only one with this issue but I never found a solution.
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 LC_NUMERIC=C LC_TIME=French_France.1252

To change language of the environment use the following command:
Sys.setenv("LANGUAGE"="En")
To change locale to English:
Sys.setlocale("LC_ALL", "English")
The name of the locale depends on what is installed on your system (for example, you might use "en_GB.UTF-8" instead of "English").

The locale you see in sessionInfo() is system wide specific, go to windows regional options and change from french to english then restart R and you should see English instead of french...but this is only if you want do it quick and dirty, it will then be applied system wide. Else ?locale should explain and to do it more surgically

Related

How can I knit a .Rnw-file into latex, with plots as tikzpicture environments? (error: formal argument matched by multiple actual arguments)

I'm trying to convert a .Rnw document to latex (to be included in another .tex-document). All plots are generated using the tikz device, but each of them as a standalone document. My goal is to have them in tikzpicture environments.
Solution attempt
According to the knitr documentation on plots, it should be possible to pass standAlone=FALSE via the dev.args-list. This produces the error message formal argument "standAlone" matched by multiple actual arguments. Knitr issue #514 describes the same error message, but their solution doesn't work here.
To reproduce, run knitr::knit("mwe.Rnw") on the following file:
\section*{MWE}
<<echo=FALSE,dev="tikz",dev.args=list(standAlone=FALSE)>>=
plot(x=1:10)
#
Error message:
Quitting from lines 3-4 (mwe.Rnw)
Error in tikzDevice::tikz(..., packages = c("\n\\nonstopmode\n", packages, :
formal argument "standAlone" matched by multiple actual arguments
According to tikzDevice documentation, standAlone=FALSE should be the default anyway, no idea why this doesn't apply here.
Any help is greatly appreciated. A seemingly related, but less specific, question has been posted but without answer.
Setup
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.2
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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
knitr_1.27
tikzDevice_0.12.3
The argument standAlone is controlled by the chunk option external, so what you need is:
<<dev="tikz", external=FALSE>>=

R and RStudio don't display greek letters and other symbols - display squares instead

I can't seem to display greek letters in r. I'm working with RStudio, and I can't seem to display greek characters no matter what I try. Initially I tried to display greek letters inside bquote, using syntax from a class I took, which the prof. published and demonstrated it worked in class. When all it showed was squares**, I tried more basic ways of displaying greek letters. I tried to use expression and than I tried to find the simplest way and ran this syntax which I found online:
mycoef <- rnorm (1000)
hist(mycoef, main = expression(beta))
In all cases it either display a square (like an unrecognized symbol), or just the word (beta, chi, etc.,). This syntax also displayed a square using R instead of RStudio.
I tried to change a bit the encoding of the file (ASCII/UTF-8), but this didn't change anything. I am working on a mac (macOS Sierra 10.12.4) if that changes anything.
**when using the bquote syntax, greek letters were not the only characters it changed to squares. Also == and ~~ without quotes were displayed as squares.
This is my sessionInfo() -
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] pt_PT.ISO8859-1/pt_PT.ISO8859-1/pt_PT.ISO8859-1/C/pt_PT.ISO8859-1/C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] plyr_1.8.4 meta_4.8-4 openxlsx_4.0.17
loaded via a namespace (and not attached):
[1] compiler_3.4.2 tools_3.4.2 Rcpp_0.12.13
=====
Note that as a try to fix this problem I ran this syntax that is displayed in the sessionInfo - Sys.setlocale("LC_ALL", "pt_PT.ISO8859-1"), which didn't help.
Thanks!
You can try using package latex2exp if you know the basics of LaTeX:
library(latex2exp)
mycoef <- rnorm (1000)
hist(mycoef, main = TeX("$\\beta$"))
I solved this problem updating the Symbols Font on Windows. (1) Download the file Symbol.ttf (https://www.fontsupply.com/fonts/S/Symbol.html),
(2) Find the file symbol.ttf in your \Windows\Fonts folder, and replace with the fresh copy.

dplyr print to console is offset

library(nycflights13)
# print head to console
flights
This is what I see:
This what should happen:
Is this an R, RStudio, dplyr or some options issue?
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin15.0.0 (64-bit)
Running under: OS X 10.11 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
other attached packages:
[1] nycflights13_0.1 dplyr_0.4.3
The issue does not originate in your code but is a minor issue/bug in RStudio, which shows the data as if you decreased the width of the console after printing the values by hand. What you can do is increase the width of the console in RStudio by hand again.
However, I have no idea what causes the error or how to resolve it in a nicer way without adjusting it by hand. The error sometimes shows up when printing a large amounts of ordered data (data.frame, data.table, tbl_df etc.) as if RStudio sets the boundaries for printing too tight.

Right to left languages support in R, using Mac

I am wondering if there is anyway to support right-to-left languages in R while using Mac
For instance suppose the following code:
x <- data.frame(a=runif(10),b=runif(10))
ggplot(x, aes(a,b)) + geom_point() + xlab("سلام")
Here is the result:
Here I tried to change the x-label as a Persian/Arabic word (سلام = Hello). While displayed correctly in the code (using R-Studio), in the graph the characters of سلام are displayed in the reverse order (left-to-right).
Also the linkage between two consecutive letters (i.e. س connected to ل would be سل) is broken.
Do you have any idea how to fix it?
Update
With the answer of #agstudy I found R under Ubuntu is perfectly OK. However I have no idea how to solve the problem in Mac (OS X 10.9.1) having updated version of R and R-Studio
It works fine for me. I just change the size of labels to better show it.
library(ggplot2)
x <- data.frame(a=runif(10),b=runif(10))
ggplot(x, aes(a,b)) +
geom_point()+ xlab('سلام') +
theme( axis.title=element_text(size=100,face="bold"))
I am using :
other attached packages:
[1] ggplot2_0.9.3.1
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Also works fine under :
R version 3.0.3 (2014-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
I had the same problem with Hebrew letters, and I manage to work around it by reading the label from an Excel file instead of typing it directly into R studio. This method works as long as you don't need to mix letters with numbers, in that case things start to get messy.
for example:
I know this is an old question, but I recently wrote an R package to deal with it. It's a simple R wrapper around some python code, since this problem also occurs when using python in mac. The package reverses the Arabic string and then reconnects the letters correctly using Abdullah Diab's python-arabic-reshaper module.
My package is here.
Abdullah Diab's module (for python) is here.

error with function regmatches using R

I'm trying to use the function regmatches, in R, but i'm getting an error (R says it can't find the function).
I'm quite tired now and maybe I'm doing some really silly mistake. However, I don't know what's wrong.
I tried to use ??regmatches, but it didn't find anything.
Next I tried the "sos" package and function findFn("regmatches"), but it returned:
found 0 matches
x has zero rows; nothing to display.
Mensagens de aviso perdidas:
In findFn("regmatches") : HIT not found in HTML; processing one page only.
I don't know what else to do.
I know I may be doing a silly mistake like this one, but I don't know what else to do. Below is my session info:
R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
1 LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.1252
attached base packages:
1 stats graphics grDevices utils datasets methods base
other attached packages:
1 sos_1.3-1 brew_1.0-6
loaded via a namespace (and not attached):
1 tools_2.12.2
regmatches was added in R 2.14.0...
I'm sorry guys. It happens that is was a silly mistake. After almost giving up, I decided to check if it was a problem with my version of R. So, I took a look at the CRAN webpage and found this under what's new with R 2.14.
New function regmatches() for extracting or replacing matched or non-matched substrings from match data obtained by regexpr(), gregexpr() and regexec().
So, It's time to update R. I thought that using version 2.12.2 wasn't that bad, but it happens it was.

Resources