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

no code highlight in terminal #190

Closed
stevenlis opened this issue Jan 16, 2020 · 35 comments
Closed

no code highlight in terminal #190

stevenlis opened this issue Jan 16, 2020 · 35 comments

Comments

@stevenlis
Copy link

stevenlis commented Jan 16, 2020

Thanks for the extension. The following gif seems really nice but I didn't have code highlight in my terminal. Am I missing something?

70815935-65391480-1e09-11ea-9ad6-7ebbebf9a9c8

R: 3.6.1
OS: Windows 10
VScode: 1.41.1

@renkun-ken
Copy link
Member

Sorry for not making it clear in README. It is radian.

ccb580e in #184 should fix this.

@stevenlis
Copy link
Author

@renkun-ken Thanks! Do this requrie R Session Watcher to be turned on to use? I thought this is a R Session Watcher..

@stevenlis
Copy link
Author

stevenlis commented Jan 16, 2020

I am running radian now but R interactive and radian in two separate terminals. Am I missing something?
image
image

@renkun-ken
Copy link
Member

renkun-ken commented Jan 16, 2020

R session watcher does not require radian.

The first R interactive in your screenshot is probably created by command R: Create R terminal. It creates an R interactive terminal by running the program specified in VSCode option r.rterm.* according to your OS. By default, it is the official R terminal.

If you want to change the default terminal, you need to change the Rterm: Windows|Linux|macOS is VSCode settings or update r.rterm.* in settings.json to the path of your radian executable.

To use radian smoothly, you should also turn on r.bracketedPaste option.

If you prefer opening radian manually by typing radian command in the terminal, you could turn on r.alwaysUseActiveTerminal option so that sending selection to terminal will directly send code to active terminal rather than detect if there's an active R terminal created by vscode-R.

@stevenlis
Copy link
Author

stevenlis commented Jan 16, 2020

I found it and set

"r.rterm.windows": "C:\\Users\\liqia\\Anaconda3\\Scripts\\radian.exe"

and then R: Run Selection/Line but get

The terminal process terminated with exit code: 2

It seems like everything is working but as long as I use it R: Run Selection/Line to run the radian.exe. I will get the error.

@renkun-ken
Copy link
Member

renkun-ken commented Jan 16, 2020

I could reproduce your error in a Windows 10 virtualbox machine.

It is caused by default R term options not supported by radian. Delete all Rterm option items in VSCode settings or append "r.rterm.option": [] to your VSCode settings.json, reload window, and radian should work.

The error does not occur under Linux and macOS, not sure why there's such different behaviors.

The same error also occurs under Linux and macOS. Maybe we should document this somewhere.

@stevenlis
Copy link
Author

stevenlis commented Jan 16, 2020

Thanks man. It's working now. But it seems like it uses C:/Users/liqia/Anaconda3/lib/R/bin/x64/R
instead of C:\Program Files\R\R-3.6.1\bin\R.exe. I just read the radian's doc but am not clear how to change it. Would you happen to know?

@renkun-ken
Copy link
Member

From https://github.com/randy3k/radian/blob/master/radian/__init__.py, we could see radian does not support --no-save and --no-restore.

As for how radian finds the R executable, it looks like it is done by https://github.com/randy3k/rchitect/blob/master/rchitect/utils.py#L22. You could set an environment variable R_HOME=C:\Program Files\R\R-3.6.1 to override.

@stevenlis
Copy link
Author

Thanks. I'll take a look. Now the dataset and plot show in separate windows instead of inside vscode.
image

Can you reproduce this?

@renkun-ken
Copy link
Member

It looks like you don't enable R session watcher. Did you follow the updated version of README about how to setup the session watcher at https://github.com/renkun-ken/vscode-R/tree/update-readme#r-session-watcher-experimental?

@stevenlis
Copy link
Author

@renkun-ken I did and it was working before. I think it's maybe due to the change of R.exe. I change it back and now no window show up at all. I will try later.

@stevenlis
Copy link
Author

stevenlis commented Jan 17, 2020

It was working before I change it to radian. Now I created Rprofile via

image

After restarting it, I get

Error in get_result(out, private$options) : 
  callr subprocess failed: could not start R, exited with non-zero status, has crashed or was killed


[]
exiting
Warning messages:
1: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect
2: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect
3: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect
4: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect

[Info  - 10:50:45 PM] Connection to server got closed. Server will restart.
Language server exited with exit code 0
Error in get_result(out, private$options) : 
  callr subprocess failed: could not start R, exited with non-zero status, has crashed or was killed

Now I set "r.sessionWatcher": false and tried View() and plot() and no windows show up at all.

@renkun-ken
Copy link
Member

renkun-ken commented Jan 17, 2020

The error message comes from the languageserver and suggests that callr::r_bg() cannot start a R process to process tasks. It might be related to how callr finds R executable.
It looks like you should set r.lsp.path to the same R executable radian uses.

To enable R session watcher, you should set "r.sessionWatcher": true and append the source(...) command to ~/.Rprofile, while to disable it, you should undo both.

@stevenlis
Copy link
Author

stevenlis commented Jan 17, 2020

I did delete .Rprofile though...
image

@renkun-ken
Copy link
Member

Do View() and plot() work in a plain R terminal instead of radian?

@stevenlis
Copy link
Author

If I change the path to

"r.rterm.windows": "C:\\Program Files\\R\\R-3.6.1\\bin\\x64\\R.exe"

and run View(mtcars) in vscode, nothing showed up. But if I open the R.exe in that folder, it works.

image

@stevenlis
Copy link
Author

@renkun-ken were you be able to repro the issue?

@renkun-ken
Copy link
Member

renkun-ken commented Jan 19, 2020

I don't have a Windows at hand at the moment.

If I understand it correctly, you have your ~/.Rprofile deleted, and then set your option

"r.rterm.windows": "C:\\Program Files\\R\\R-3.6.1\\bin\\x64\\R.exe"

reload or restart vscode, and execute Create R terminal command, and run View(mtcars) and nothing shows up?

If you start a same R process manually in vscode terminal, View(mtcars) works?

PS: Just saw your comment at randy3k/radian#64 (comment). Maybe more related to radian on Windows.

@stevenlis
Copy link
Author

stevenlis commented Jan 19, 2020

@renkun-ken What you said is correct. But since I changed the path to the default R.exe and it works, I think it might not be related to radian. Btw, it seems like demo() works, but not View() and plot()

@stevenlis
Copy link
Author

@renkun-ken It seems like radian works if I deleted my R folder from my path variable, but I just tried it in vscode. It still doesn't work with

"r.rterm.windows": "C:\\Program Files\\R\\R-3.6.1\\bin\\x64\\R.exe"

but if I change it to

"r.rterm.windows": "C:\\Users\\liqia\\Anaconda3\\Scripts\\radian.exe"

View() and plot() windows will show up

@randy3k
Copy link
Member

randy3k commented Jan 19, 2020

It doesn't seem to be me that it is a radian specific issue as you also got an error in R.exe.

@stevenlis
Copy link
Author

stevenlis commented Jan 19, 2020

Now it seems like as long as I add "C:\Program Files\R\R-3.6.1\bin\x64 into my path variable and move it to the top. Neither R in vscode nor radian will work except for the R.exe in that folder.

If I remove "C:\Program Files\R\R-3.6.1\bin\x64 from my PATH variable, radian will work again. If I use radian as my r.rterm.windows, it will work, but if I use R.exe, View() and plot() won't work.

@stevenlis
Copy link
Author

@renkun-ken I logged an issue #195 here and I've also uninstalled radian completely, so I believe it an R extension issue.

@renkun-ken
Copy link
Member

I'm a bit confused about the environment you are starting the R process. Would you mind posting your sessionInfo(), str(options()), and Sys.getenv() in the R process which you find problematic?

@stevenlis
Copy link
Author

stevenlis commented Jan 20, 2020

@renkun-ken right now. No matter what I use, plot() and View() just won't work.

r$> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.6.1 tools_3.6.1    jsonlite_1.6
r$> str(options())
List of 67
 $ add.smooth                          : logi TRUE
 $ browser                             :function (url, ...)
  ..- attr(*, "srcref")= 'srcref' int [1:8] 24 21 24 73 21 73 24 24
  .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x0000017745295480> 
 $ browserNLdisabled                   : logi FALSE
 $ CBoundsCheck                        : logi FALSE
 $ check.bounds                        : logi FALSE
 $ citation.bibtex.max                 : int 1
 $ continue                            : chr "+ "
 $ contrasts                           : Named chr [1:2] "contr.treatment" "contr.poly"
  ..- attr(*, "names")= chr [1:2] "unordered" "ordered"
 $ defaultPackages                     : chr [1:6] "datasets" "utils" "grDevices" "graphics" ...
 $ demo.ask                            : chr "default"
 $ deparse.cutoff                      : int 60
 $ device                              :function (...)
  ..- attr(*, "srcref")= 'srcref' int [1:8] 20 20 23 11 20 11 20 23
  .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x0000017745295480> 
 $ device.ask.default                  : logi FALSE
 $ digits                              : int 7
 $ echo                                : logi TRUE
 $ editor                              : chr "notepad"
 $ encoding                            : chr "native.enc"
 $ example.ask                         : chr "default"
 $ expressions                         : int 5000
 $ help.search.types                   : chr [1:3] "vignette" "demo" "help"
 $ help.try.all.packages               : logi FALSE
 $ help_type                           : chr "html"
 $ HTTPUserAgent                       : chr "R (3.6.1 x86_64-w64-mingw32 x86_64 mingw32)"
 $ install.packages.compile.from.source: chr "interactive"
 $ internet.info                       : int 2
 $ keep.parse.data                     : logi TRUE
 $ keep.parse.data.pkgs                : logi FALSE
 $ keep.source                         : logi TRUE
 $ keep.source.pkgs                    : logi FALSE
 $ locatorBell                         : logi TRUE
 $ mailer                              : chr "mailto"
 $ matprod                             : chr "default"
 $ max.print                           : int 99999
 $ menu.graphics                       : logi FALSE
 $ na.action                           : chr "na.omit"
 $ nwarnings                           : int 50
 $ OutDec                              : chr "."
 $ page_viewer                         :function (url, ...)  
  ..- attr(*, "srcref")= 'srcref' int [1:8] 26 25 26 78 25 78 26 26
  .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x0000017745295480> 
 $ pager                               : chr "internal"
 $ papersize                           : chr "letter"
 $ PCRE_limit_recursion                : logi NA
 $ PCRE_study                          : int 10
 $ PCRE_use_JIT                        : logi TRUE
 $ pdfviewer                           : chr "C:/Program Files/R/R-3.6.1/bin/x64/open.exe"
 $ pkgType                             : chr "both"
 $ prompt                              : chr "\033[34mr$>\033[0m "
 $ rchitect.py_tools                   :<environment: 0x000001774778dea8>
 $ repos                               : Named chr "@CRAN@"
  ..- attr(*, "names")= chr "CRAN"
 $ scipen                              : num 0
 $ show.coef.Pvalues                   : logi TRUE
 $ show.error.messages                 : logi TRUE
 $ show.signif.stars                   : logi TRUE
 $ str                                 :List of 3
  ..$ strict.width: chr "no"
  ..$ digits.d    : int 3
  ..$ vec.len     : int 4
 $ str.dendrogram.last                 : chr "`"
 $ stringsAsFactors                    : logi TRUE
 $ timeout                             : num 60
 $ ts.eps                              : num 1e-05
 $ ts.S.compat                         : logi FALSE
 $ unzip                               : chr "internal"
 $ useFancyQuotes                      : logi FALSE
 $ verbose                             : logi FALSE
 $ viewer                              :function (url, ...)
  ..- attr(*, "srcref")= 'srcref' int [1:8] 25 20 25 73 20 73 25 25
  .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x0000017745295480>
 $ vscodeR                             :<environment: 0x0000017745ce2948>
 $ warn                                : num 0
 $ warning.length                      : int 1000
 $ width                               : int 207
 $ windowsTimeouts                     : int [1:2] 100 500
r$> Sys.getenv()
ALLUSERSPROFILE                                               C:\ProgramData
APPDATA                                                       C:\Users\liqia\AppData\Roaming     
asl.log                                                       Destination=file
COLORTERM                                                     truecolor
CommonProgramFiles                                            C:\Program Files\Common Files      
CommonProgramFiles(x86)                                       C:\Program Files (x86)\Common Files
CommonProgramW6432                                            C:\Program Files\Common Files      
COMPUTERNAME                                                  DESKTOP-2AE5U2K
ComSpec                                                       C:\WINDOWS\system32\cmd.exe
DASHLANE_DLL_DIR                                              C:\Users\liqia\AppData\Roaming\Dashlane\6.1907.0.17833\bin\Firefox_Extension\{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components;C:\Users\liqia\AppData\Roaming\Dashlane\6.1907.0.17833\ucrt;C:\Users\liqia\AppData\Roaming\Dashlane\6.1907.0.17833\bin\Qt;C:\Users\liqia\AppData\Roaming\Dashlane\6.1907.0.17833\bin\Ssl
DriverData                                                    C:\Windows\System32\Drivers\DriverData
GEODA_GDAL_DATA                                               C:\Program Files\GeoDa Software\data
GEODA_OGR_DRIVER_PATH                                         C:\Program Files\GeoDa Software
graphviz                                                      C:\Users\liqia\Anaconda3\Library\bin\graphviz
HOME                                                          C:\Users\liqia\Documents
HOMEDRIVE                                                     C:
HOMEPATH                                                      \Users\liqia
LANG                                                          en_US.UTF-8
LOCALAPPDATA                                                  C:\Users\liqia\AppData\Local
LOGONSERVER                                                   \\DESKTOP-2AE5U2K
MSYS2_ENV_CONV_EXCL                                           R_ARCH
NUMBER_OF_PROCESSORS                                          8
OneDrive                                                      C:\Users\liqia\OneDrive
OneDriveConsumer                                              C:\Users\liqia\OneDrive
OS                                                            Windows_NT
pandoc                                                        C:\Users\liqia\AppData\Local\Pandoc\Pandoc
PATH                                                          C:\Program
                                                              Files\R\R-3.6.1\bin\x64;C:\Perl64\site\bin;C:\Perl64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program
                                                              Files (x86)\Calibre2\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program
                                                              Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common
                                                              Files\Intel\WirelessCommon\;C:\Program
                                                              Files\Git\cmd;C:\Users\liqia\Anaconda3;C:\Users\liqia\Anaconda3\Library\mingw-w64\bin;C:\Users\liqia\Anaconda3\Library\usr\bin;C:\Users\liqia\Anaconda3\Library\bin;C:\Users\liqia\Anaconda3\Scripts;C:\Users\liqia\AppData\Local\Microsoft\WindowsApps;C:\Users\liqia\AppData\Roaming\Dashlane\5.13.0.20992\bin\Firefox_Extension\{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components;C:\Users\liqia\AppData\Roaming\Dashlane\5.13.0.20992\ucrt;C:\Users\liqia\AppData\Local\atom\bin;C:\Users\liqia\AppData\Local\Programs\MiKTeX
                                                              2.9\miktex\bin\x64\;C:\Users\liqia\AppData\Roaming\Dashlane\5.15.0.21720\bin\Firefox_Extension\{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components;C:\Users\liqia\AppData\Roaming\Dashlane\5.15.0.21720\ucrt;C:\Users\liqia\AppData\Local\GitHubDesktop\bin;C:\Users\liqia\AppData\Local\Programs\Microsoft
                                                              VS Code\bin;C:\Program Files
                                                              (x86)\Scapple;C:\Users\liqia\AppData\Local\Microsoft\WindowsApps;C:\Users\liqia\AppData\Roaming\Dashlane\6.1907.0.17833\bin\Firefox_Extension\{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components;C:\Users\liqia\AppData\Roaming\Dashlane\6.1907.0.17833\ucrt;C:\Users\liqia\AppData\Roaming\Dashlane\6.1907.0.17833\bin\Qt;C:\Users\liqia\AppData\Roaming\Dashlane\6.1907.0.17833\bin\Ssl;C:\Users\liqia\AppData\Local\Pandoc\;;c:\users\liqia\anaconda3\lib\site-packages\pywin32_system32
PATHEXT                                                       .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE                                        AMD64
PROCESSOR_IDENTIFIER                                          Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
PROCESSOR_LEVEL                                               6
PROCESSOR_REVISION                                            8e0a
ProgramData                                                   C:\ProgramData
ProgramFiles                                                  C:\Program Files
ProgramFiles(x86)                                             C:\Program Files (x86)
ProgramW6432                                                  C:\Program Files
PSModulePath                                                  C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC                                                        C:\Users\Public
R_ARCH                                                        /x64
R_COMPILED_BY                                                 gcc 4.9.3
R_DOC_DIR                                                     C:\Program Files\R\R-3.6.1\doc
R_HOME                                                        C:/Program Files/R/R-3.6.1
R_INCLUDE_DIR                                                 C:\Program Files\R\R-3.6.1\include
R_LIBS_USER                                                   C:\Users\liqia\Documents/R/win-library/3.6
R_SHARE_DIR                                                   C:\Program Files\R\R-3.6.1\share
R_USER                                                        C:\Users\liqia\Documents
RADIAN_VERSION                                                0.4.4
SESSIONNAME                                                   Console
SystemDrive                                                   C:
SystemRoot                                                    C:\WINDOWS
TEMP                                                          C:\Users\liqia\AppData\Local\Temp
TERM_PROGRAM                                                  vscode
TERM_PROGRAM_VERSION                                          1.41.1
TMP                                                           C:\Users\liqia\AppData\Local\Temp
USERDOMAIN                                                    DESKTOP-2AE5U2K
USERDOMAIN_ROAMINGPROFILE                                     DESKTOP-2AE5U2K
USERNAME                                                      liqia
USERPROFILE                                                   C:\Users\liqia
windir                                                        C:\WINDOWS

@stevenlis stevenlis reopened this Jan 20, 2020
@renkun-ken
Copy link
Member

renkun-ken commented Jan 20, 2020

Combined with the VSCode settings you post at #195, (I guess all above info and VSCode settings are effective at the same time?), it looks like you sourced vscode-R session watcher script init.R (because you have vscodeR option set in R, and viewer, browser, device replaced by sourcing the script) while session watcher is disabled ("r.sessionWatcher": false). randy3k/radian#139 is caused by this too.

You need to remove the source(...) line in your ~/.Rprofile and .Rprofile (if any) in working directory AND disable r.sessionWatcher in VSCode, and restart a session. Currently, if VSCode session watcher script init.R is sourced, then all interactive R session will require the use of VSCode session watcher in VSCode, or the plot and viewer will not be captured.

vignette() calls browser, so it won't work if r.sessionWatcher is not enabled either.

@stevenlis
Copy link
Author

@renkun-ken I don't think I have a ~/.Rprofile, is there any command I can run to find its path?

@renkun-ken
Copy link
Member

renkun-ken commented Jan 20, 2020

You may try the following R code:

file.edit("~/.Rprofile")
file.edit(".Rprofile")

You may start a new R process with C:\...\R.exe --vanilla and see. This disables all profile and not restoring any history.

@stevenlis
Copy link
Author

Indeed, I don't have it
image

@renkun-ken
Copy link
Member

If you are sure that no .Rprofile exists as ~/.Rprofile and .Rprofile, then I guess it might come from .RData when your session restores history data it restores all options.

You may remove .RData in your working directory and see.

@stevenlis
Copy link
Author

Ok, I finally found out that I have a Rprofile file under C:\Program Files\R\R-3.6.1\library\base\R.
image
I added the following line when enabling sessionWatcher. I removed it and now everything works as expected.

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

@renkun-ken Thanks a lot.

@ChristopheRoyer21
Copy link

I have

I could reproduce your error in a Windows 10 virtualbox machine.

It is caused by default R term options not supported by radian. Delete all Rterm option items in VSCode settings or append "r.rterm.option": [] to your VSCode settings.json, reload window, and radian should work.

The error does not occur under Linux and macOS, not sure why there's such different behaviors.

The same error also occurs under Linux and macOS. Maybe we should document this somewhere.

I did something like this to enable Radian because I could, and it seems to work. However, everytime I write a line in Radian, it directly gets delete so I don't even have time to see the result. Any idea why it's doing this?

@renkun-ken
Copy link
Member

@ChristopheRoyer21 Would you like to post the issue to radian and give more details so that @randy3k could take a closer look at it?

@ChristopheRoyer21
Copy link

@renkun-ken Well, unfortunately, I cannot anymore since the problem got solved by itself. I have no idea what happens. I'm new to Radian so I probably changed some options without noticing it

@renkun-ken
Copy link
Member

Closing now. If it stops working again, please feel free to reopen.

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

No branches or pull requests

4 participants