I am using Windows 10 OS, and when I tried to use the session watcher, the R terminal cannot be attached. (neither auto attach or manually getOption('vscodeR')$attach())
I observed response.log was changing over time (as below), but obviously there was no attached R session or any expected window pop-up for dataview.
{"time":"2020-01-08 18:10:23","pid":7220,"command":"attach"}
{"time":"2020-01-08 18:10:26","pid":7220,"command":"attach"}
{"time":"2020-01-08 18:10:44","pid":7220,"command":"dataview","source":"table","type":"json","title":"mtcars","file":"C:\\Users\\kooho\\AppData\\Local\\Temp\\RtmpOKdp0S\\file1c3430431451.json"}
{"time":"2020-01-08 18:10:49","pid":7220,"command":"attach"}
{"time":"2020-01-08 18:15:47","pid":3172,"command":"attach"}
{"time":"2020-01-08 18:19:31","pid":5868,"command":"attach"}
{"time":"2020-01-08 18:19:34","pid":5868,"command":"attach"}
@Koohoko Good timing, we just updated the README today with a fix for Windows! Could you try changing the line in your .Rprofile to the below and see if that fixes it?
source(file.path(if (.Platform$OS.type == "windows") file.path(Sys.getenv("HOMEDRIVE"), Sys.getenv("HOMEPATH")) else Sys.getenv("HOME"), ".vscode-R", "init.R"))
Thank you.
@Koohoko Thanks for reporting!
It looks like init.R is correctly sourced in your .Rprofile but vscode-R does not manage to watch the response.log you refer to. The following cases may lead to such problem:
r.sessionWatcher is enabled, you'll see a status item R: (not attached).{workspaceFolder}/.vscode/vscode-R/response.log. If user starts an R session in another directory (e.g. a subdirectory), the R session will create a response file like {workspaceFolder}/subfolder/.vscode/vscode-R/response.log, which does not work with vscode-R running in {workspaceFolder}.If all above do not apply, would you like to post the output of the following command:
ls.str(getOption("vscodeR"))
and the path of your workspace folder you open in VSCode?
@renkun-ken Thank you so much! The issue is fixed.
It turns out that it was indeed the inconsistent workspace that caused the problem.
After putting the .Rprofile to my current directory (rather than the ~ folder) fixed the problem.
Thanks for your amazing work.
@andycraig Thanks for your comment, the updated version works just fine, but later I found out that my problem was caused by other wrong configurations.
@renkun-ken
Sorry I do not know why but I am still getting this on my own workspace (screencap below)..
I found that the session watcher works fine when my workspace is on home folder ~, but when I change to other folder it failed to attach.

@Koohoko It looks like there's a .Rprofile in your workspace folder.
According to https://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html, if a local .Rprofile is found, then ~/.Rprofile will be ignored. We should document that if a local .Rprofile is used, it must contain a line source("~/.Rprofile") or the code in README to ensure the session watcher code is executed.
We'll document this in README soon and probably add a command for user to edit ~/.Rprofile more easily.
Thanks @renkun-ken . I think I am on a right direction.
It seems that things are more complicated on my environment, where my R_UESR path (~/Documents/) is different from the ~/ home directory of the system. I am not sure if it matters.
I did some experiment on my machine:
~~.Rprofile location: ~ (only)r$> ls.str(getOption("vscodeR"))
attach : function ()
dataview : function (x, title)
dataview_data_type : function (x)
dataview_table : function (data)
dir : chr "C:\\Users\\kooho\\.vscode\\vscode-R"
dir_session : chr "C:\\Users\\kooho\\.vscode\\vscode-R/14704"
globalenv_file : chr "C:\\Users\\kooho\\.vscode\\vscode-R/14704/globalenv.json"
pid : int 14704
plot_file : chr "C:\\Users\\kooho\\.vscode\\vscode-R/14704/plot.png"
plot_updated : logi FALSE
rebind : function (sym, value, ns)
respond : function (command, ...)
response_file : chr "C:\\Users\\kooho\\.vscode\\vscode-R/response.log"
tempdir : chr "C:\\Users\\kooho\\AppData\\Local\\Temp\\Rtmp881VBt"
update : function (...)
r$> Sys.getenv("R_USER")
[1] "C:\\Users\\kooho\\Documents"
r$> getwd()
[1] "C:/Users/kooho"
init.R not sourced?).../user_directory.../user_directory.Rprofile location: ~ (only)r$> ls.str(getOption("vscodeR"))
Error in as.environment(pos) : using 'as.environment(NULL)' is defunct
r$> Sys.getenv("R_USER")
[1] "C:\\Users\\kooho\\Documents"
r$> getwd()
[1] "G:/My Drive/work/2020/user_directoy/script"
r$> getOption('vscodeR')$attach()
Error: attempt to apply non-function
init.R sourced but r terminal not attached).../user_directory.../user_directory.Rprofile location: ~/Documents (only)r$> getOption('vscodeR')$attach()
r$> ls.str(getOption("vscodeR"))
attach : function ()
dataview : function (x, title)
dataview_data_type : function (x)
dataview_table : function (data)
dir : chr "G:\\My Drive\\work\\2020\\user_directoy\\script\\.vscode\\vscode-R"
dir_session : chr "G:\\My Drive\\work\\2020\\user_directoy\\script\\.vscode\\vscode-R/7064"
globalenv_file : chr "G:\\My Drive\\work\\2020\\user_directoy\\script\\.vscode\\vscode-R/7064/globalenv.json"
pid : int 7064
plot_file : chr "G:\\My Drive\\work\\2020\\user_directoy\\script\\.vscode\\vscode-R/7064/plot.png"
plot_updated : logi FALSE
rebind : function (sym, value, ns)
respond : function (command, ...)
response_file : chr "G:\\My Drive\\work\\2020\\user_directoy\\script\\.vscode\\vscode-R/response.log"
tempdir : chr "C:\\Users\\kooho\\AppData\\Local\\Temp\\RtmpUHHXvJ"
update : function (...)
r$> getwd()
[1] "G:/My Drive/work/2020/user_directoy/script"
r$> Sys.getenv("R_USER")
[1] "C:\\Users\\kooho\\Documents"
init.R sourced but r terminal not attached).../user_directory.../user_directory.Rprofile location: ~/user_directory (only)@Koohoko Thanks for your detailed experimentation.
Let me clarify more on the paths.
On Windows, R will source ~/.Rprofile on session startup if no local .Rprofile is found. This file is typically expanded to C:\\Users\\username\\Documents\\.Rprofile. You can find out yourself via
normalizePath("~/.Rprofile")
Let's ensure this file is correctly edited to contain the code to source init.R:
source(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R"))
When you say your VSCode workspace and R working directory are both .../user_directory, I notice from your output that might not be the case since ls.str(getOption("vscodeR")) says R working directory is G:\\My Drive\\work\\2020\\user_directoy\\script rather than G:\\My Drive\\work\\2020\\user_directoy. Please ensure that the workspace folder in your VSCode is exactly where you start your R session. It looks like you start your R session in .../user_directoy\\script rather than .../user_directory.
Thanks @renkun-ken for the detailed explanation.
Sorry I was not sure whether I am getting the workspace folder set up correctly, would you please take a look at the below screenshot which I tried to reproduce the Case 3 scenario.


Thanks for your kind help!
@Koohoko From your screenshots, the workspace folder in your VSCode is .../user_directory/script since the script files are shown in the root in your workspace folder. And your R session is also started from the same folder. In this case, session watcher should work but somehow it doesn't work in your case.
Would you like to go to Help > Toggle Develop Tools and take a screenshot like the following when you create an R session or manually call attach.

When the session is attached, there will be logging about reading response file and got pid, etc.
It looks like vscode-R cannot watch the response.log for some reason. Let's see if there's anything wrong showing up in the logs.
It seems like the log shows nothing when I launch R.. (shown in Fig 1)
Fig 1.

I also noticed that it pop up some error messages when I tried pointing some code (Fig 2 and Fig 3), I believe they may be related to the LSP service?
Fig 2.

Fig 3.

It looks like responseWatcher that watches {workspaceFolder}/.vscode/vscode-R/response.log does not work as expected.
Maybe I should file an PR that adds more logging to session watcher to show which part does not work in your case.
Just notice that @Ikuyadeu released a new version very recently, would you please try the latest version and see if the problem still persists, @Koohoko?
@Koohoko I build a version based on current master but adds more logging to session watcher (https://github.com/Ikuyadeu/vscode-R/compare/master...renkun-ken:more-logging).
You may try this build and see the logging in the developer tools.
@renkun-ken
Thanks, the new log is shown as below:

@Koohoko Thanks. It looks like the responseWatcher does not manage to capture any changes in response.log. Quite strange. Would you like to try creating a folder in your Documents (e.g. C:\\Users\\kooho\\Documents\\vscodeR-test), create an R script in this folder and open this folder in VSCode and see if session watcher works? I'm guessing there's something quirky happening in your folder G:\\My Drive\\work\\2020\\user_directoy\\script which does not seem to support file watcher.
@renkun-ken
Oh yes, it works!

I think I know what happened here.. The G:\\ drive I am using here is like a virtual drive provided by Google Drive (Drive File Stream). I think it may cause responseWatcher not functioning. Do you think this would be fixable?

@Koohoko It seems that VSCode does not work well with workspace open in a Google Drive (e.g. https://github.com/microsoft/vscode/issues/74117, https://github.com/microsoft/vscode/issues/69333). According to https://github.com/microsoft/vscode/issues/79421, the virtual filesystem provider does not seem to implement watch feature so that FileSystemWatcher does not work with files in it. Therefore, we can do nothing about it at the moment.
@renkun-ken
Thanks so much!
I may just use the local filesystem instead.
Thanks again for this amazing project!
Most helpful comment
@Koohoko Thanks for reporting!
It looks like
init.Ris correctly sourced in your.Rprofilebut vscode-R does not manage to watch theresponse.logyou refer to. The following cases may lead to such problem:r.sessionWatcheris enabled, you'll see a status itemR: (not attached).{workspaceFolder}/.vscode/vscode-R/response.log. If user starts an R session in another directory (e.g. a subdirectory), the R session will create a response file like{workspaceFolder}/subfolder/.vscode/vscode-R/response.log, which does not work with vscode-R running in{workspaceFolder}.If all above do not apply, would you like to post the output of the following command:
and the path of your workspace folder you open in VSCode?