Why is locator() broken in RStudio? - r

Does anyone know how to fix when RStudio is breaking the locator() function? If I plot
plot(1:10)
then use locator() to click on the same points (1:10), this is what I get after I click the Finish button.
locator(type = 'p', col = 'red')
$x
[1] 1.265369 2.226131 3.172336 4.147655 5.064746 6.040065
[7] 6.986270 7.947032 8.893237 9.868556
$y
[1] 1.437224 2.361029 3.265178 4.169328 5.093133 5.997282
[7] 6.901432 7.825237 8.729386 9.633536
However, if I do the same thing in the R GUI rather than RStudio, then it works just fine:
I've tried restarting my session, using dev.off(), and restarting RStudio but the problem persists. Am I missing something simple here, or maybe it's a bug in RStudio?
R version 3.3.1
RStudio 0.99.903
Mac OSX 10.11.6

Related

R plot shows uncommon hex like numbers on axis

I couldn't find an answer for this very easy question, because I don't know how to describe or even name the question. The code is extremly simple but it happens everytime I use the "plot" function in my jupyter notebook.
n <- 10
alpha <- rnorm(n,60,10)
beta <- rnorm(n,0,10)
Hbar <- 150
Hseq <- seq(from=130,to=170,len=30)
plot(NULL,xlim=c(130,170),ylim=c(10,100),xlab="height (cm)", ylab="weight (kg)")
for (i in 1:n)
lines(Hseq, alpha[i] + beta[i] * (Hseq-Hbar),
lwd=3, col=sample(1:10, 1))
The result looks like this:
For sure the axis should show "numeric numbers" instead of these "hex!?" onces. I think it have something to do with my R or jupyter version so:
Ubuntu LTS 20.4
anaconda 4.10.3
r-base 3.6.1
jupyter_client 7.1.0
jupyter_core 4.9.1
newest firefox version
Or maybe the keycode-table? What can I do?
Could this be helpful?
Sys.getlocale()
'LC_CTYPE=C.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C'
Update:
After restarting the conda enviroment and the r-kernel, it works without any changes in the code or packages. Even if I tried this before, I don't get it. So the cause or solution stays unclear.

Rstudio - plots not showing and plots menu grayed out

I'm using Rstudio Version 1.0.136. I'm trying to plot some data and when I execute the code nothing shows up in the 'Plot' pane and the 'Plots' drop down menu is grayed out. Any suggestions?
EDIT:
> dev.off()
null device
1
> dev.cur()
null device
1
I tried restarting R and then ran this code and got this error message:
> library(ggplot2);qplot(mpg, hp, data = mtcars)
Warning message:
R graphics engine version 12 is not supported by this version of RStudio. The Plots tab will be disabled until a newer version of RStudio is installed.

Setting up GUIs in R

Trying to create some GUIs in R.
I create a window and it disappears.
What am I missing here?
library(tcltk)
tt <- tktoplevel() <br>
x <- tkbutton(tt, text = "Text") <br>
tkpack(x)
What system do you use? It works just fine on macOS with R 3.4.1
This is strange. It should work fine from command line as well:
I assume that you have XQuartz (https://www.xquartz.org) installed and configured.

corrupted UTF characters in pdf plots generated by R

I am trying to save plots with legends containing UTF characters for Males and Females to pdf in R. When I plot to graphics device :
plot(1)
legend('topright', bty = 'n',
expression(italic("legend"~"\u2640"~"\u2642")))
the legend of plot looks as expected
I can even save it to pdf by right click and "save to pdf". However, when I use inbuilt function pdf
pdf('test.pdf')
plot(1)
legend('topright', bty = 'n',
expression(italic("legend"~"\u2640"~"\u2642")))
dev.off()
it drops a warning and shows corrupted characters instead:
cairo_pdf does not drop a warning, but it does not show the correct symbols either:
According to this post, I should specify encoding that would support my symbols, however I have no idea how to find out which it does (besides default Helvetica I tried MacRoman without success).
It is apparent that it is possible for R to generate pdf that contains these symbols (because I am able to do so by the right click). However, I would like to achieve that in automatized manner.
My R session settings:
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.5 (El Capitan)
locale:
[1] en_US.UTF-8/C/en_US.UTF-8/C/en_US.UTF-8/C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
I also managed to reproduce same behaviour on another computer with macOS Sierra 10.12.1.
A working answer on OS X is using quartz:
quartz(type = 'pdf', file = 'test.pdf')
Source : https://stackoverflow.com/a/19610909/2962344
cairo_pdf seems to work on Linux.
hi this is working for me (on windows)
cairo_pdf('test.pdf' , family="DejaVu Sans")
plot(1)
legend('topright', bty = 'n',
paste("legend",quote("\u2640") ,quote("\u2642") ))
dev.off()
Unicode Characters in ggplot2 PDF Output
on mac try this
pdf('test.pdf',encoding="MacRoman")
Plotting symbols fails in PDF
I had the same problem, the other solutions did not work for me, and finally I used png instead of pdf:
png('test.png', units="in", width=11, height=10, res = 600)
plot(1)
legend('topright', bty = 'n',
expression(italic("legend"~"\u2640"~"\u2642")))
dev.off()

how to permanently save options(dplyr.width = Inf) in Rstudio?

In Rstudio and the dplyr package :
> save options(dplyr.width = Inf)
helps to visualize ALL columns in a Data Frame.
Great!
But this useful saved Options setting,
vanishes when you quit the current Rstudio session.
Next time you start Rstudio, it's gone...
Q:
How to permanently save:
options(dplyr.width = Inf) in Rstudio?
(so that the saved option setting
is available in ALL my future Rstudio sessions)?
Thanks!
- Ubuntu Linux 12.04 (32-bit)
- Rstudio v: 0.99.441 + R v: 3.2.0 (2015-04-16)
- Pale Moon 25.5.0 and FF 37.0.2

Resources