Running Nvim-R via PuTTy: setting up r_term_cdm - r

I would like to run Nvim-R on a remote machine via putty when I try to open a *.R file the remote machine returns an error message:
Please set the variable g:R_term_cmd in your vimrc. Read the plugin
documentation ...
According to the documentation, the R_term_cmd should be used in the following manner:
If |R_in_buffer| = 0 and the X Window System is running and tmux is
installed, then R will run in an external terminal emulator. The
plugin uses the first terminal emulator that it finds in the following
list:
1. gnome-terminal,
2. konsole,
3. xfce4-terminal,
4. Eterm,
5. (u)rxvt,
6. aterm,
7. roxterm,
8. terminator,
9. lxterminal
10. xterm.
If Vim does not select your favorite terminal emulator, you may define
it in your vimrc by setting the variable R_term, as shown below:
let R_term = "xterm"
If your terminal emulator is not listed above, or if you are not satisfied with the way your terminal emulator
is called by the plugin, you may define in your vimrc the variable
R_term_cmd, as in the examples below:
let R_term_cmd = "xterm -title R -e"
let R_term_cmd = "xfce4-terminal --icon=/path/to/icons/R.png --title=R -x"
However, this variable does not appear to be utilised by the sample configuration files available through the Vim-R-Tmux: An Integrated Working Environment for R. Furthermore, the settings in vimrc:
" start R with F2 key
map <F2> <Plug>RStart
imap <F2> <Plug>RStart
vmap <F2> <Plug>RStart
" send selection to R with space bar
vmap <Space> <Plug>RDSendSelection
" send line to R with space bar
nmap <Space> <Plug>RDSendLine
<LocalLeader> settings
The suggested <LocalLeader> settings not appear to work as pressing F2 does not launch connected R session.
Software versions
tmux 2.3
VIM - Vi IMproved 8.0

You have two options
Use Tmux, which you apparently are
This way, Nvim-R can actually use a tmux pane to start an R console.
Please refer to section 9.21 Integration with Tmux in the documentation.
You need to put the following in your vimrc:
let R_in_buffer = 0
let R_applescript = 0
let R_tmux_split = 1
Or just use NeoVim
NeoVim has a builtin terminal, which actually just works with the Nvim-R plugin.

Related

Chrome debugging port not open after 10 seconds

I am using following code: It works good on local system and one unix server, but fails on another server. Any idea what I might need to do
> library(chromote)
> set_default_chromote_object(
Chromote$new(browser = Chrome$new(args = "--no-sandbox"))
and I am getting following error:
Chrome debugging port not open after 10 seconds.
Two things you can check:
On the server in question, start chrome and go to chrome://version/ . Search the Command Line: section and make sure --enable-logging is in there.
Strat R on the server in question, and do:
library(chromote)
debug(chromote:::launch_chrome)
Now run that R-code in as normal and when it stops and waits for input, hit n and then enter and repeat hitting enter until you get to the lines you link to on github. After line 87 when output gets defined, type output on the terinal and hit enter. Inspect the output and make sure that it actually conatins the lines DevTools listening on ws:// . If it does not, see if there are other ways that logging text identifies the port it listens to. If so, I would git clone that package, go in and change the way it discovers the port number and modify the package that runs for that server.
Running Chrome without X server
There are two viable options here:
vnc
X.org dummy driver
Here is the VNC recipe:
1: VNC
a. sudo dnf install tigervnc-server (for centos 8), sudo yum install tigervnc-server (for centos 7)
b. vncserver :1 (or some other suitable number)
c. DISPLAY=:1 R # and run R code to launch chrome etc.
Now you can connect from your client and see that chrome runs as it should:
vncviewer centos.ip.address:1
2: X.org dummy
I have never done this myself, but in theory it should be straight forward if you read docs and follow a tutorial.

responding yes to terminal prompt via system2() in R

tl;dr: How can I invoke the system command y | conda create --name gee_interface from an R console, e.g. via system2()? I'm comfortable enough with system2('conda', c('create', '--name', 'gee_interface')), but I don't know how to handle piping in the 'y' via system2().
Details
I am trying to use an R console to run the bash command conda create --name gee_interface (OSX Mojave with Anaconda installed).
In terminal, that command executes just fine, but prompts me to answer with Proceed ([y]/n)? (I answer 'y' and everything works smoothly).
In R, I run
Sys.setenv(PATH = paste(c("/Applications/anaconda3/bin", Sys.getenv("PATH")), collapse = .Platform$path.sep)) # ensures that system2() finds conda
system2('conda', c('create', '--name', 'gee_interface')) # This is the key line for the purposes of this question
When running the second line [i.e. system2('conda', c('create', '--name', 'gee_interface'))], the process never finishes, but quickly falls to zero CPU usage. Presumably the system is waiting for my response to the prompt, but I don't know how to provide it. How does one do this via an R script? Note also that in my particular case, the number of times that I need to respond 'y' is variable, depending on whether an environment of the name gee_interface already exists or not.
The fix to your first problem is to tell conda not to ask for confirmation using -y:
system2('conda', c('create', '--name', 'gee_interface', '-y'))
As to the second part (variable times that your input is required), I'm guessing it's to overwrite the environment if it exists? In that case, you could check for its existence first with conda info --envs, and run conda remove --name gee_interface --all if necessary before creating it.
See:
https://docs.conda.io/projects/conda/en/latest/commands/create.html
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#removing-an-environment
You could also try your system2 call, with the argument input = "y", but that doesn't fix your second problem of needing to affirm multiple times.
See: Invoke a system command and pipe a variable as an argument

Run gym-gazebo on Google Colaboratory

I am trying to run gym-gazebo on Google Colaboratory.
There is a problem to run gazebo server (gazebo without gui) on Colab.
There was warning on display: Unable to create X window. Rendering will be disabled but I think I fix it.
There also warning about sound card. not sure it related Unable to open audio device,
And there warning about conversion Conversion of sensor type[depth] not supported
Here is an example
Can you help?
In order to run gazebo in a headless mode you need to run gserver executable, instead of gazebo. Not sure which one is used by the gym-gazebo toolkit.
In order to still do rendering in gazebo server (e.g. camera view) you would need to use Xvfb (X Virtual Frame Buffer). It is an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory.
For your specific colab notebook I have changed last cell by adding
get_ipython().system_raw('Xvfb :1 -screen 0 1600x1200x16 &')
in order to create virtual display and added DISPLAY=:1.0 to the beginning of the last line, so it looked as follows
DISPLAY=:1.0 python gym-gazebo/examples/turtlebot/circuit2c_turtlebot_camera_dqn.py
DISPLAY=:1.0 tells X Window client used by gazebo to use virtual display we have created instead of default one :0.
A complete installation of Gazebo on colab and running it in headless server mode with rendering capability can be achieved the following way:
!curl -sSL http://get.gazebosim.org | sh # Install gazebo
!apt-get install -y xvfb # Install X Virtual Frame Buffer
get_ipython().system_raw('Xvfb :1 -screen 0 1600x1200x16 &') # create virtual display with size 1600x1200 and 16 bit color. Color can be changed to 24 or 8
!source /usr/share/gazebo-9/setup.sh && DISPLAY=:1.0 gzserver --verbose # Run gazebo and tell X client to use our virtual DISPLAY :1.0
There is also a way to run full gazebo in simulator with gzweb as a head and link to it using ngrok.io explained here as a fully working notebook. https://colab.research.google.com/drive/1A-miW8cTRKzs7B0m1m4enfiFySzBhsgN
You would need to authenticate to ngrok using your auth token which can be created at ngrok.com in order to connect, because it is lunch as background and doesn't print to cell
!./ngrok authtoken <token>

R system functions always returns error 127

I need to execute an external tool from R and process errors (if any) occurred in that tool.
I know 3 functions to do something familiar with my task:
shell, system and system2.
Trying to test those, I see that command
shell("notepad")
opens notepad. As far as I know shell doesn't allow to check errors (there's no interface to look into stderr).
When I call
system("notepad")
or
system2("notepad")
R freezes trying to make those commands.
Calling
system("start notepad")
or
system2("start notepad")
returns warning
Warning message:
running command '"start notepad"' had status 127
Adapting #DavidTseng's answer (sorry for not having enough reputation to upvote it)...
system("cmd.exe", input = "notepad")
worked for me in Windows.
As I mentioned in my comments, the R documentation reveals that in Windows the system() function does not launch a separate shell (if needed). This is why command line commands run with system(), but Notepad, which needs a separate window, does not run:
From the documentation for system():
The most important difference is that on a Unix-alike system launches a shell which then runs command. On Windows the command is run directly – use shell for an interface which runs command via a shell (by default the Windows shell cmd.exe, which has many differences from a POSIX shell).
system("bash -l", input = "notepad")
I'm not sure if there's been an update to R that allows this since the question was asked nearly four years ago, but system("\"C:\path\to\exe.exe\" args", intern = T) works for me and WILL bring up a separate child window and works on Windows 10 + R 3.6 + RStudio.
Not using the 'intern = T' was giving me a return code of 127 and did not run the process.
I had the same issue. there is an additional step in the installation process which i did not do.
refer to to the url
https://cran.r-project.org/bin/windows/Rtools/
Look for "Putting Rtools on the PATH"
writeLines('PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"', con = "~/.Renviron")
for windows users
wrong: system(path("c:", "program files", "r", "anysoft.EXE"))
but works : system(path("c:", shQuote("program files"), "r", "anysoft.EXE"))
You guys are making it so complicated. I solved this problem by referring to this answer. The problem is with the PATH. type Sys.which('') in R, and you will see nothing. So you have to set the path in CMD, and then use Sys.setenv(PATH = '') in R to get this work.

Proxy setting for R

I am facing problem while conecting R with internet in my office. May be this due to LAN settings. I tried the almost all possible ways I come across in the web (see below) but still in vain.
Method1: Invoking R using --internet2
Method2: Invoking R by setting ~/Rgui.exe http_proxy=http:/999.99.99.99:8080/ http_proxy_user=ask
Method3: Setting Setinternet2=TRUE
Method4:
curl <- getCurlHandle()
curlSetOpt(.opts = list(proxy = '999.99.99.99:8080'), curl = curl)
Res <- getURL('http://www.cricinfo.com', curl = curl)
In above all methods I can able to load packages directly from CRAN also able to download files using download.file command
But using getURL(RCurl), readHTMLTable(XML), htmlTreeParse(XML) commands I am unable to extract web data. I am getting ~<HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD>~ error.
How to set LAN proxy settings for XML package in R?
On Mac OS, I found the best solution here. Quoting the author, two simple steps are:
1) Open Terminal and do the following:
export http_proxy=http://staff-proxy.ul.ie:8080
export HTTP_PROXY=http://staff-proxy.ul.ie:8080
2) Run R and do the following:
Sys.setenv(http_proxy="http://staff-proxy.ul.ie:8080")
double-check this with:
Sys.getenv("http_proxy")
I am behind university proxy, and this solution worked perfectly. The major issue is to export the items in Terminal before running R, both in upper- and lower-case.
For RStudio just you have to do this:
Firstly, open RStudio like always, select from the top menu:
Tools-Global Options-Packages
Uncheck the option: Use Internet Explorer library/proxy for HTTP
And then close the Rstudio, furthermore you have to:
Find the file (.Renviron) in your computer, most probably you would find it here: C:\Users\your user name\Documents. Note that if it does not exist you can creat it just by writing this command in RStudio:
file.edit('~/.Renviron')
Add these two lines to the initials of the file:
options(internet.info = 0)
http_proxy="http://user_id:password#your_proxy:your_port"
And that's it..??!!!
The problem is with your curl options – the RCurl package doesn't seem to use internet2.dll.
You need to specify the port separately, and will probably need to give your user login details as network credentials, e.g.,
opts <- list(
proxy = "999.999.999.999",
proxyusername = "mydomain\\myusername",
proxypassword = "mypassword",
proxyport = 8080
)
getURL("http://stackoverflow.com", .opts = opts)
Remember to escape any backslashes in your password. You may also need to wrap the URL in a call to curlEscape.
I had the same problem at my office and I solved it adding the proxy in the destination of the R shortcut; clik on right button of the R icon, preferences, and in the destination field add
"C:\Program Files\R\your_R_version\bin\Rgui.exe" http_proxy=http://user_id:passwod#your_proxy:your_port/
Be sure to put the directory where you have the R program installed. That works for me. Hope this help.
This post pertains to R proxy issues on *nix. You should know that R has many libraries/methods to fetch data over internet.
For 'curl', 'libcurl', 'wget' etc, just do the following:
Open a terminal. Type the following command:
sudo gedit /etc/R/Renviron.site
Enter the following lines:
http_proxy='http://username:password#abc.com:port/'
https_proxy='https://username:password#xyz.com:port/'
Replace username, password, abc.com, xyz.com and port with these settings specific to your network.
Quit R and launch again.
This should solve your problem with 'libcurl' and 'curl' method. However, I have not tried it with 'httr'. One way to do that with 'httr' only for that session is as follows:
library(httr)
set_config(use_proxy(url="abc.com",port=8080, username="username", password="password"))
You need to substitute settings specific to your n/w in relevant fields.
Inspired by all the responses related on the internet, finally I've found the solution to correctly configure the Proxy for R and Rstudio.
There are several steps to follow, perhaps some of the steps are useless, but the combination works!
Add environment variables http_proxy and https_proxy with proxy details.
variable name: http_proxy
variable value: https://user_id:password#your_proxy:your_port/
variable name: https_proxy
variable value: https:// user_id:password#your_proxy:your_port
If you start R from a desktop icon, you can add the --internet flag to the target line (right click -> Properties)
e.g."C:\Program Files\R\R-2.8.1\bin\Rgui.exe" --internet2
For RStudio just you have to do this:
Firstly, open RStudio like always, select from the top menu:
Tools-Global Options-Packages
Uncheck the option: Use Internet Explorer library/proxy for HTTP
Find the file (.Renviron) in your computer, most probably you would find it here: C:\Users\your user name\Documents.
Note that: if it does not exist you can create it just by writing this command in R:
file.edit('~/.Renviron')
Then add these six lines to the initials of the file:
options(internet.info = 0)
http_proxy = https:// user_id:password#your_proxy:your_port
http_proxy_user = user_id:password
https_proxy = https:// user_id:password0#your_proxy:your_port
https_proxy_user = user_id:password
ftp_proxy = user_id:password#your_proxy:your_port
Restart R. Type the following commands in R to assure that the configuration above works well:
Sys.getenv("http_proxy")
Sys.getenv("http_proxy_user")
Sys.getenv("https_proxy")
Sys.getenv("https_proxy_user")
Sys.getenv("ftp_proxy")
Now you can install the packages as you want by using the command like:
install.packages("mlr",method="libcurl")
It's important to add method="libcurl", otherwise it won't work.
On Windows 7 I solved this by going into my environment settings (try this link for how) and adding user variables http_proxy and https_proxy with my proxy details.
If you start R from a desktop icon, you can add the --internet flag to the target line (right click -> Properties) e.g.
"C:\Program Files\R\R-2.8.1\bin\Rgui.exe" --internet2
Simplest way to get everything working in RStudio under Windows 10:
Open up Internet Explorer, select Internet Options:
Open editor for Environment variables:
Add a variable HTTP_PROXY in form:
HTTP_PROXY=http://username:password#localhost:port/
Example:
HTTP_PROXY=http://John:JohnPassword#localhost:8080/
RStudio should work:
Tried all of these and also the solutions using netsh, winhttp etc.
Geek On Acid's answer helped me download packages from the server but none of these solutions worked for using the package I wanted to run (twitteR package).
The best solution is to use a software that let's you configure system-wide proxy.
FreeCap (free) and Proxifier (trial) worked perfectly for me at my company.
Please note that you need to remove proxy settings from your browser and any other apps that you have configured to use proxy as these tools provide system-wide proxy for all network traffic from your computer.
Find your R home with R.home("home")
Add following lines to Renviron.site in your R home
http_proxy=http://proxy.dom.com/
http_proxy_user=user:passwd
https_proxy=https://proxy.dom.com/
https_proxy_user=user:passwd
Open R -> R reads Renviron.site in its home -> it should work :)
My solution on a Windows 7 (32bit). R version 3.0.2
Sys.setenv(http_proxy="http://proxy.*_add_your_proxy_here_*:8080")
setInternt2
updateR(2)

Resources