Right to left languages support in R, using Mac - r

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.

Related

bgroup does not render properly on ggplot

The results of bgroup from plotmath do not seem to render properly as a ggplot2 annotation. For example ...
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
annotate("text", x=2.5, y=25, label="bgroup('(',atop(x,y),')')", parse=TRUE) +
annotate("text", x=3.5, y=25, label="group('(',atop(x,y),')')", parse=TRUE)
... produces the following graph for me ...
Note how the bgroup rendering on the left does not have large parentheses like I would expect (and worked in some previous version of R), whereas the reqular group rendering to the right does seem to work.
Am I missing a font? Something else?
I am using R 4.2.2 and ggplot2 3.4.0.
EDITS:
The code above worked properly in R versions 4.0.5, 4.1.0, 4.1.2, and 4.2.0 (and 3.6.3 according to Jamie in the comments .. but not on Linux according to an answer on R-help).
The issue does not seem related to ggplot2 as the same problem occurs with base graphics.
The same issue occurs with R version 4.2.2 whether the code is run in RStudio or the RGui.
The same issue occurs (in R version 4.2.2) when the plot is directed to a PNG but not when it is directed to a PDF.
plot(0,xlim=c(0,1),ylim=c(0,1))
text(0.5,0.5,expression(bgroup('(',atop(x,y),')')))
It's working fine for me on Linux; I guess you guys are all using Windows?
Note that "rendering" strongly depends on the graphics device.
What is your .Device {after plotting}?
I suggest a Windows graphapp font problem, similar to the one just fixed yesterday, also Windows-only:
https://bugs.r-project.org/show_bug.cgi?id=18440

Rmarkdown fails to render inline plots when opened within an R project on GoogleDrive

I have an R project held onto a Google Drive. I access both the R project and associated markdowns using the Google Drive desktop app. I recently updated my macOS to Monterey 12.2.1 and since then, I haven't been able to render plots inline within a markdown. I get the following error message when trying to print any plot:
Error in dev.off() :
QuartzBitmap_Output - unable to open file '/Volumes/GoogleDrive/Shared drives/.../.Rproj.user/shared/notebooks/-.../1/s/cqgw7b5dagxzw_t/_rs_chunk_plot_001.png'
This seems to be specific when opening a markdown, within an R project, onto a Google Drive. I have tried having a project on my local machine and opening the same markdown, plots display inline fine. I have tried opening the markdown outside of a project, again, can display plots inline fine. The plots also display in the viewer pane fine regardless and knitting is also not an issue.
The only clue I have is that when I go within the .Rproj.user directory, I can find a folder with the naming 'cqgw7b5dagxzw' (see path above), but it is missing the '_t'. Not sure what that could mean though.
Since updating the OS I have also reinstalled XQuartz.
I can still get to the plots, so it's not a HUGE issue, but the inline display feature is rather handy to make quick modifications to my visualisations.
Below are some session info.
Thanks!!!
PS: Plot twist! I can display plots inline with ggplotly?!?!
Workaround
I found this workaround which displays the plots in the viewer pane instead. It is definitely an improvement, but displaying plots inline allows you to get an idea of the proportions of the plot you will eventually knit.
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.2.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
I found an issue someone logged on Rstudio github relates to this, linked here.
It seems you're right about the niche scenario of Rmarkdown + R Project + Google Drive + Inline plotting.
Someone in the comments suggested going to Preferences>General>Graphics and changing the back end option to Cairo instead of Quartz. Tried that on my end and seems to work when I tried a basic histogram with GGplot2.
Not sure if using Cairo makes anything else worse though.
Using MacOS Monteray (12.3.1) if that helps.

An issue with tiff and ggplot R functions inside for loop

]
2
I was not able to get a batch of images with tiff() R function inside for loop.
I have x86_64-w64-mingw32/x64 (64-bit) platform with installed Windows 8.1 and RStudio Version 1.0.143 with R version 3.6.0 (2019-04-26) -- "Planting of a Tree". I tried to obtaine a batch of tiff images by putting my code inside the for loop. Unfortunately that resulted in the numerous broken files (in attachment). But if i type exactly the same code in the RStudio console i got normal (valid) image.
#Fragment of the script
for (i in 1:nrow(BH))
{
...
tiff( paste(pos$rs[1],"tiff",sep = '.'))
ggplot(df_g_,aes(x=factor(g),fill=factor(O)))+geom_bar(stat="count")+xlab("")+labs(fill='')
dev.off()
}
#If i perform the following code in console after script execution i got a valid image
tiff( paste(pos$rs[1],"tiff",sep = '.'))
ggplot(df_g_,aes(x=factor(g),fill=factor(O)))+geom_bar(stat="count")+xlab("")+labs(fill='')
dev.off()
The solution was to envelop ggplotfunction by base print function in the loop:
print(ggplot(df_g_,aes(x=factor(g),fill=factor(O)))+geom_bar(stat="count")+xlab("")+labs(fill=''))
So, i've used the solution from the other post:
enter link description here

R doesn't recognize Latin7 characters

I have really strange problem. I am using Lithuanian keyboard, but R doesn't recognize letters such as į, š, č.
For example when I write:
žodis <- "žibutė"
in R console I see
þodis <- "þibutë".
I have R in several computers, all work fine except this one. Can you help me with this issue? Is any function to let R know that I'm using Lithuanian keyboard? My computer's operating system is Windows 10 and R version 3.3.2.

How to embed/display code in texmaker?

I am new to texmaker. I have difficulty in displaying the codes and results I got from R in my texmaker document.
For example I have this results:
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)
How do I display that in texmaker that it looks like the one you are seeing? (indented, gray background, looks like a code from R).
What do I need to have?
Thanks!
Would the listings package (which supports R) achieve what you want?: http://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings
In LaTeX you can also just use the verb(atim) environment for fixed-width, not interpreted text:
/begin{verb}
> R code goes here...
/end{verb}
?
If you want to display both the command and the results, then don't you need to execute the R code? (Unless you are planning to copy and paste the results...).
I would suggest checking out the knitr package.

Resources