Setting the Terminal to use WSL bash in Windows 10

This is on 1.4.1103 and Windows 10 Pro.

I am using some linux only R packages. I built and can successfully run them in wsl2 bash (I have ubuntu 20.04 installed, if that makes any difference). I would like to use the Rstudio IDE on windows to send those directly to R in WSL2.

I imagine this is possible through the terminal window, since one of the terminal options is indeed called Bash (Windows Subsystem for Linux). However, when I try to open a new terminal window with Bash WSL option, I barely see an error message flickers that's either "command not found" or "system cannot find path" (too short to read it in full) and terminal window remains blank.

I have not found any documentation that might help me to resolve this, any help/insight would be much appreciated.

Hi,

Welcome to the RStudio community!

Too bad to hear it's not working. I've been using WSL2 commands with success here, and I have the same setup (apart from Windows 10 home instead of pro). Are you able to run WSL commands through the "system()" call?

Like this:

system("wsl ls ./")

If that works, you should be able to send commands from R to WSL without the use of the terminal window.

Hope this helps,
PJ

Thanks @pieterjanvc
I am getting this:

> system("wsl ls ./")
T[1] 65535

I tried more commands like this:

> system("wsl --list")
W[1] 0
> system("wsl --help")
C[1] 65535

EDIT: More digging into wsl, I found out that the default system was an old and defuncts Centos installation. Setting the default wsl session to be Ubuntu, everything is working as expected (including the terminal).

Can you also give me an example of how to use the system call directly? Would it be possible to output the plots to the plot pane?

Thank you very much for the support!

1 Like

Hi,

If I understand your question, you have some R packages you have to run on Linux right? In that case, the whole R session needs to be running there, as you cannot simply transfer objects from the Linux R session to a Windows one. Unless you'd save the data in Windows, load it into R in Linux, save the data again once finished, but that's not very elegant. You can use WSL to perform some other actions of course and collect the result back in R, either by loading the results after processing or by using the intern = TRUE option from the system() call to capture the terminal output.

If you want to use Rstudio on you WSL system, so that you can see plots etc when you perform tasks, you can setup RStudio server on it and then connect to your Linux R session. Here is a guide to set that up

Hope this helps,
PJ

Yes, this is exactly what I was wondering. If the Rstudio can use the R in wsl natively. It appears not. Rstudio server is definitely a good solution. Thank your for your help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.