vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

the radian in vscode could not recognize the directory that I set in ‘Rprofile.site’

Open mewinners opened this issue 3 years ago • 29 comments

Most of time, the radian only in vscode could not recognize the directory that I set in ‘Rprofile.site’. It recognized successfully only once, but I don’t know why, because I didn’t change any settings. Here are some relating screenshots. I am looking forward to your reply.

Radian in vscode: 1

Radian in windows terminal (powershell and cmd): 2 3

R studio: 4

Rprofile.site: 5

Settings relating radian in vscode: 6 7 8

mewinners avatar Jun 05 '22 03:06 mewinners

Does it occur with official R console in vscode?

renkun-ken avatar Jun 05 '22 04:06 renkun-ken

Is your Rprofile.site located at the site directory? Since your r.rterm.options specifies --no-site-file, it will not be sourced on R session startup.

renkun-ken avatar Jun 05 '22 04:06 renkun-ken

Is there a reason not to use .Rprofile in your case?

renkun-ken avatar Jun 05 '22 04:06 renkun-ken

Does it occur with official R console in vscode?

yes.

mewinners avatar Jun 05 '22 04:06 mewinners

Is your Rprofile.site located at the site directory? Since your r.rterm.options specifies --no-site-file, it will not be sourced on R session startup.

It is located at R\R-4.2.0\etc\Rprofile.site, indeed. So,how can I solve this problem?

mewinners avatar Jun 05 '22 04:06 mewinners

Is there a reason not to use .Rprofile in your case?

Probably no. I am just used to change the setting in Rprofile.site

mewinners avatar Jun 05 '22 04:06 mewinners

Does it work if you use ~/.Rprofile to specify the same settings?

As you specifiy --no-init-file in your vscode setting r.rterm.option, your site file will not be removed. You should use the default value of that that setting unless you intend so.

renkun-ken avatar Jun 05 '22 04:06 renkun-ken

I will have a try, But I am not familiar with .Rprofile, is there any way use Rprofile.site?

mewinners avatar Jun 05 '22 04:06 mewinners

You should restore the default value of r.rterm.option in your vscode settings. Looks like --no-init-file prevents R session from sourcing Rprofile.site on startup.

renkun-ken avatar Jun 05 '22 04:06 renkun-ken

You should restore the default value of r.rterm.option in your vscode settings. Looks like it is --no-init-file prevents R session from sourcing Rprofile.site on startup.

I have changed the .Rprofile ,radian in vscode successfully recognizes the directory in R. Thank you very much! And, I followed the user guide of Radian, changed the r.rterm.option, removed --no-save and --no-store, then add '--no-site-file'. In your opinion, I shoud restore the r.rterm.option, re-add --no-save and --no-store ? or just remove the '--no-site-file', change r.rterm.option to blank?

mewinners avatar Jun 05 '22 05:06 mewinners

Does it work if you use ~/.Rprofile to specify the same settings?

As you specifiy --no-init-file in your vscode setting r.rterm.option, your site file will not be removed. You should use the default value of that that setting unless you intend so.

I have changed the .Rprofile ,radian in vscode successfully recognizes the directory in R. Thank you very much! Here I have another problem, I run the rscript in windows ternimal with radian could display the plot I need, but there is no plot displaying while I run the same rscript in vscode with radian.

mewinners avatar Jun 05 '22 05:06 mewinners

We recommend using httpgd to show plot. You might want to install httpgd and turn on r.useHttpgd in your vscode settings.

renkun-ken avatar Jun 05 '22 05:06 renkun-ken

We recommend using httpgd to show plot. You might want to install httpgd and turn on r.useHttpgd in your vscode settings.

I have already done those.

mewinners avatar Jun 05 '22 05:06 mewinners

Does session watcher attach to your R session successfully? You could check out by running ls.str(.vsc) in your R terminal.

renkun-ken avatar Jun 05 '22 05:06 renkun-ken

emmm, Error in ls.str(.vsc) : object '.vsc' not found

mewinners avatar Jun 05 '22 06:06 mewinners

Are you using R: Create R terminal to start a new R terminal?

renkun-ken avatar Jun 05 '22 06:06 renkun-ken

Are you using R: Create R terminal to start a new R terminal?

no, just radian

mewinners avatar Jun 05 '22 06:06 mewinners

Then you should follow the steps at https://github.com/REditorSupport/vscode-R/wiki/R-Session-watcher#advanced-usage-for-self-managed-r-sessions to make session watcher work with self-managed R terminals.

renkun-ken avatar Jun 05 '22 06:06 renkun-ken

Are you using R: Create R terminal to start a new R terminal?

I have set the PATH environment variable of anaconda, install the radian through conda.

mewinners avatar Jun 05 '22 06:06 mewinners

Then you should follow the steps at https://github.com/REditorSupport/vscode-R/wiki/R-Session-watcher#advanced-usage-for-self-managed-r-sessions to make session watcher work with self-managed R terminals.

OK, I will have a try, thank you.

mewinners avatar Jun 05 '22 06:06 mewinners

Then you should follow the steps at https://github.com/REditorSupport/vscode-R/wiki/R-Session-watcher#advanced-usage-for-self-managed-r-sessions to make session watcher work with self-managed R terminals.

It didn't work. I have appended the following code to the .Rprofile: if (interactive() && Sys.getenv("RSTUDIO") == "") { source(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R")) }

mewinners avatar Jun 05 '22 06:06 mewinners

Would you like to see the value of

file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R")

and see if the file exists?

If so, what if you manually source the file in a new session?

renkun-ken avatar Jun 05 '22 07:06 renkun-ken

Would you like to see the value of

file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R")

and see if the file exists?

If so, what if you manually source the file in a new session?

Yes, it locates 'D:\Program Files\Microsoft Visual Studio Code\data\extensions\reditorsupport.r-2.5.0\R\session\init.R' but I don't know how to manually source the file?

mewinners avatar Jun 05 '22 07:06 mewinners

Then you could try starting a new R session, and run

source("D:\\Program Files\\Microsoft Visual Studio Code\\data\\extensions\\reditorsupport.r-2.5.0\\R\\session\\init.R")

renkun-ken avatar Jun 05 '22 08:06 renkun-ken

Then you could try starting a new R session, and run

source("D:\\Program Files\\Microsoft Visual Studio Code\\data\\extensions\\reditorsupport.r-2.5.0\\R\\session\\init.R")

still not work. but I find that, if I start a new terminal in vscode, and copy the rscript in it and run, there will be a window to display the plot. 1

if I use ctrl+enter in the r file in vscode, there will no windows

mewinners avatar Jun 05 '22 08:06 mewinners

It is strange that your USERPROFILE does not point to a user folder but the installation location of the extension.

renkun-ken avatar Jun 05 '22 08:06 renkun-ken

It is strange that your USERPROFILE does not point to a user folder but the installation location of the extension.

maybe there are some errors in the path. By the way, does this picture come from httpgd? mean that the httpgd was successfully applied?

mewinners avatar Jun 05 '22 11:06 mewinners

It is R's built-in plot window, not from vscode-R or httpgd.

renkun-ken avatar Jun 05 '22 11:06 renkun-ken

It is R's built-in plot window, not from vscode-R or httpgd.

emmm, so it failed again. and I found this, does it have influences? Snipaste_2022-06-05_22-34-03

mewinners avatar Jun 05 '22 14:06 mewinners

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Jun 06 '23 02:06 github-actions[bot]