View/ save R plot on the Linux server - r

I am working on a remote Linux server with R. I have made a plot in R using ggplot().
p <- ggplot(new_df) + geom_line(aes(x=dt, y=user_cnt))
However, when I want to view the plot as
>p
I get the following error:
Error: is.integer(group) is not TRUE
Also when I want to save the plot to a file with the following code:
jpeg("myplot.jpg")
ggplot(new_df) + geom_line(aes(x=dt, y=user_cnt)
dev.off()
I still get the error: Error: is.integer(group) is not TRUE
This problem does not occur when I'm working with the RGui on Windows.
How can I view/save my plot on the Linux server? I am connected from Windows 10 using PuTTy.

You can't view any pictures on TTY. So you need ftp tools.
To download Git, and install it. Then, open Git Bash, and use sftp user#ip to connect to your servicer. Finally use get filesName to get your files.
P.S. Excuse me for my poor English, please.

Just to visualize you can use plot().
I.e. plot(p)
However I am also having issues with saving the plot (will update this if I figure out a solution).

Related

Vscode-R; permission denied to access request.log file

I am learning R and followed the instructions to program R using Visual Studio Code. I then tried to run the following line of code to learn how to read data.
dat <- read.table("d.data")
View(dat)
where d.data is a data file. I received the following error:
cannot open file '...\.vscode-R/request.log': Permission denied.
I tried using the "Give Access To" command from right-clicking the file in File Explorer, however, I don't think it did anything. How do I grant the program/terminal permission to open the file? It may be significant to note that running the same commands using the radian console works without any issues (I get the data outputted in a separate window).
I found a workaround for this issue by adjusting these settings in VSCode:
"r.alwaysUseActiveTerminal": true,
"r.bracketedPaste": true,
Then, by calling radian in an opened cmd terminal, I was able to load everything without any issues

Passing -X argument for ssh with emacs and tramp

I am using emacs ess and tramp to remotely execute some R script.
I typically have an R script on a server, and I run it interactively on my server, through emacs. This work all well and fine.
However I can not manage to have the plot windows appears from my R script. I would like to obtain from emacs the same behavior that if I ran
ssh -X user#server.com
and then do some R interactively, with plot appearing on my local machine.
I have modified my .ssh/config to add the ForwardX11 yes option, which works for a direct ssh query on my sever but not with emacs/trump
I have also tried the option to customize tramp-default-mode` (see https://superuser.com/questions/609414/emacs-doesnt-use-ssh-config-when-accessing-files-on-a-remote-machine) but this does not work either.
I also came across this very similar question:
How can I launch an x-window from emacs ess when running R on a server?
However:
1) The accepted answer is not a direct answer to the forwardX problem
2) The second answer is not working (am I doing something wrong ? or missing a configuration somewhere?)
Thanks for your help,
edit I use Emacs 23.1.1 on a Ubuntu 16.04
(with-eval-after-load 'tramp
(add-to-list 'tramp-methods
'("sshx11"
(tramp-login-program "ssh")
(tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
("-e" "none") ("-X") ("%h")))
(tramp-async-args (("-q")))
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-login ("-l"))
(tramp-remote-shell-args ("-c"))
(tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
("-o" "UserKnownHostsFile=/dev/null")
("-o" "StrictHostKeyChecking=no")
("-o" "ForwardX11=yes")))
(tramp-default-port 22)))
(tramp-set-completion-function "sshx11" tramp-completion-function-alist-ssh))
This is just a copy of the "ssh" method, with the "-X" added to tramp-login-args. Then you can visit a file/directory with C-x C-f /sshx11:user#host:path/to/target.

R Plot locally in remote SSH connection

I configured SSH with the -X switch as instructed in How can I make R plot locally in a remote ssh connection?. But I cannot see any plots yet. But when I use the command xeyes & it displays the eyes as expected.
I tried the following after executing R program.
library(MASS)
school = painters$School
school.fre = table(school)
cbind(school.fre)
barplot(school.fre)
and also in command line using the command R CMD BATCH barplot.r after saving the above codes in a file named barplot.r
What am I doing wrong? Please kindly guide me in this regard.
Thanks.
Briefly:
using xeyes or xterm as a test is good: you now know x11 (and forwarding) works
ensure R itself has x11 support and look at capabilities()[["X11"]] which should be TRUE
patience: R plots are bitmaps, this is not always fast. Maybe start with
plot(1:10) for the simplest point plot.

RStudio : Rook does not work?

I would like to build a simple webserver using Rook, however I am having strange errors when trying it in R-Studio:
The code
library(Rook)
s <- Rhttpd$new()
s$start()
print(s)
returns the rather useless error
"Error in listenPort > 0 :
comparison (6) is possible only for atomic and list types".
When trying the same code in a simple R-Console,everything works - so I would like to understand why that happens and how I can fix it.
RStudio is Version 0.99.484 and R is R 3.2.2
I've experienced same thing.
TLDR: This pull request solves the problem: https://github.com/jeffreyhorner/Rook/pull/31
RStudio is treated in different way and Rook port is same as tools:::httpdPort value. The problem is that in current Rook master tools:::httpdPort is assigned directly. It's a function that's why we need to evaluate it first.
If you want to have it solved right now, without waiting for merge into master: install devtools and load package from my fork #github.
install.packages("devtools")
library(devtools)
install_github("filipstachura/Rook")

knitr execution halted because of http_proxy?

I had to mess around with my R version to be able to get my secure gateway to connect to R mirrors. I did this by adding http_proxy=http://servername to both the properties tab in the R icon, and also by doing:
Sys.setenv(http_proxy=http://servername)
in Rstudio. Could get this to work in R, but not Rstudio. anyway no problem - I can install packages from within R, point RStudio at R and load the package. good.
So I try to create a (default) .Rmd file in Rstudio - when I run knitr, I get the following:
Error: 24:17: unexpected '/'
24: http_proxy=http:/
^
Execution halted
I can only imagine I am getting this because I messed around setting up the proxy. Would this make sense?
How do I clear/unset any proxy server in Rstudio?
Quote the string:
Sys.setenv(http_proxy = "http://servername")
If your on Windows, configure your proxy in IExplorer and use setInternet2(TRUE) function in your script to use IExplorer's proxy settings.

Resources