Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to attach terminal with Google Drive (Drive File Stream) #179

Closed
Koohoko opened this issue Jan 8, 2020 · 18 comments · Fixed by #348
Closed

Unable to attach terminal with Google Drive (Drive File Stream) #179

Koohoko opened this issue Jan 8, 2020 · 18 comments · Fixed by #348

Comments

@Koohoko
Copy link

Koohoko commented Jan 8, 2020

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"} 
@andycraig
Copy link
Collaborator

@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.

@renkun-ken
Copy link
Member

renkun-ken commented Jan 8, 2020

@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:

  1. You don't launch R session with the vscode-R extension activated. Open an R file to activate the extension. If r.sessionWatcher is enabled, you'll see a status item R: (not attached).
  2. The working directory of the R session and your workspace folder you open in VSCode is not the same. The session watcher requires that the session to be watched must be started in the workspace folder you open in VSCode as the working directory. It only watches {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?

@Koohoko
Copy link
Author

Koohoko commented Jan 9, 2020

@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.

@Koohoko
Copy link
Author

Koohoko commented Jan 9, 2020

@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.

@Koohoko
Copy link
Author

Koohoko commented Jan 9, 2020

@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.

image

@renkun-ken
Copy link
Member

renkun-ken commented Jan 9, 2020

@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.

@Koohoko
Copy link
Author

Koohoko commented Jan 10, 2020

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:

Case 1 (session watcher working fine)

  • VSCode workspace: ~
  • R working directory: ~
  • .Rprofile location: ~ (only)
  • Results:
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"

Case 2 (session watcher not working, seems init.R not sourced?)

  • VSCode workspace: .../user_directory
  • R working directory: .../user_directory
  • .Rprofile location: ~ (only)
  • Results:
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

Case 3 (session watcher not working, seems init.R sourced but r terminal not attached)

  • VSCode workspace: .../user_directory
  • R working directory: .../user_directory
  • .Rprofile location: ~/Documents (only)
  • Results:
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"

Case 4 (session watcher not working, seems init.R sourced but r terminal not attached)

  • VSCode workspace: .../user_directory
  • R working directory: .../user_directory
  • .Rprofile location: ~/user_directory (only)
  • Results: same as Case 3

@renkun-ken
Copy link
Member

renkun-ken commented Jan 10, 2020

@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.

@Koohoko
Copy link
Author

Koohoko commented Jan 13, 2020

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.

Untitled
Untitled1

Thanks for your kind help!

@renkun-ken
Copy link
Member

@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.

image

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.

@Koohoko
Copy link
Author

Koohoko commented Jan 13, 2020

It seems like the log shows nothing when I launch R.. (shown in Fig 1)
Fig 1.
WeChat Image_20200113171936

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.
WeChat Image_20200113172007
Fig 3.
WeChat Image_20200113172348

@renkun-ken
Copy link
Member

renkun-ken commented Jan 13, 2020

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?

@renkun-ken
Copy link
Member

renkun-ken commented Jan 13, 2020

@Koohoko I build a version based on current master but adds more logging to session watcher (master...renkun-ken:more-logging).

You may try this build and see the logging in the developer tools.

vscode-R-1.2.1-more-logging.zip

@Koohoko
Copy link
Author

Koohoko commented Jan 14, 2020

@renkun-ken
Thanks, the new log is shown as below:
WeChat Image_20200114125800

@renkun-ken
Copy link
Member

@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.

@Koohoko
Copy link
Author

Koohoko commented Jan 14, 2020

@renkun-ken
Oh yes, it works!
image

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?
image

@Koohoko Koohoko changed the title Unable to attach terminal on Windows OS Unable to attach terminal with Google Drive (Drive File Stream) Jan 14, 2020
@renkun-ken
Copy link
Member

renkun-ken commented Jan 14, 2020

@Koohoko It seems that VSCode does not work well with workspace open in a Google Drive (e.g. microsoft/vscode#74117, microsoft/vscode#69333). According to microsoft/vscode#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.

@Koohoko
Copy link
Author

Koohoko commented Jan 14, 2020

@renkun-ken
Thanks so much!
I may just use the local filesystem instead.

Thanks again for this amazing project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants