Open janvydra opened 5 years ago
You may try putting the path to R in settings.
Hello. Not sure what the resolution here was (if any). After updating R, I now have trouble with R-IDE/LSP (rlang). I get no specific error, but rlang is only initialized correctly when I launch ST3 from Terminal. I was wondering if you had any thoughts about this? I am assuming that this behavior is a result of the PATH not being visible to ST3 packages. I have tried multiple work-arounds and hacks from StackOverflow and elsewhere to get the PATH to be visible to ST3, none have worked. I also tried to set the path to R in the settings for R-IDE but this has had no effect. Thanks.
try turning on the debug settings of LSP and R-IDE to see what error message you get?
Thanks for the reply - I did and I am not sure if it has done anything. I did catch this output in the console (which does NOT appear on launch from Terminal):
reloading plugin Terminus.main
plugins loaded
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 298, in on_api_ready
plc()
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Installed Packages/LSP.sublime-package/boot.py", line 25, in plugin_loaded
startup()
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Installed Packages/LSP.sublime-package/plugin/core/main.py", line 25, in startup
load_handlers()
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Installed Packages/LSP.sublime-package/plugin/core/registry.py", line 42, in load_handlers
for handler in LanguageHandler.instantiate_all():
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Installed Packages/LSP.sublime-package/plugin/core/handlers.py", line 26, in instantiate_all
instantiate(c) for c in cls.__subclasses__()
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Installed Packages/LSP.sublime-package/plugin/core/handlers.py", line 27, in <genexpr>
if issubclass(c, LanguageHandler))
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Installed Packages/LSP.sublime-package/plugin/core/handlers.py", line 31, in instantiate
return c()
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Packages/R-IDE/ride/lsp.py", line 78, in __init__
"-I{}".format(R(script="cat(R.home('include'))"))
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Packages/R-IDE/ride/r.py", line 65, in R
stdout, stderr = p.communicate(input=stdin_text)
File "./python3.3/subprocess.py", line 920, in communicate
File "./python3.3/subprocess.py", line 1577, in _communicate
File "./python3.3/subprocess.py", line 848, in _translate_newlines
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 176: ordinal not in range(128)
It seems to me a locale issue. And the error occurred when running R --slave -e "R.home('include')"
and I t gives a non ASCII char when it is not called in terminal. What is your $LANG
variable?
You could check the Sublime $LANG
by running
import os; os.environ["LANG"]
in Sublime console.
In the other hand, in terminal, just do echo $LANG
.
In Terminal echo $LANG
returns en_US.UTF-8
but I cannot duplicate this in Sublime - I get the error
>>> os.environ["LANG"]
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "./python3.3/os.py", line 656, in __getitem__
KeyError: 'LANG'
Not sure if this matters. I tried explicitly setting the LANG in the R-IDE settings file, but this did not have any discernible effect.
It could very well be a local issue; since I duplicate settings across machines the issue is also duplicated for me elsewhere. Just very strange that it was fine and working well a few days ago and a complete R distribution reinstall nuked the ST3 packages.
In any case, I appreciate your time and suggestions.
The KeyError was expected. How about the following in console
import subprocess; subprocess.check_output(["R", "--slave", "-e", "R.home('include')"])
The result was
>> import subprocess
>>> subprocess.check_output(["R", "--slave", "-e", "R.home('include')"])
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "./python3.3/subprocess.py", line 576, in check_output
File "./python3.3/subprocess.py", line 819, in __init__
File "./python3.3/subprocess.py", line 1448, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: 'R'
Of course, when launching from the Terminal the process does generate the expected R console messages. Looks like I need to point ST3 at R differently? I thought putting the path to the R binary in the R-IDE settings would suffice; my bash profile does attach the R binary path to $PATH, which is why it works when calling from Terminal, I suppose.
How about changing "R"
to your path to R?
Yes, that generates the expected R console messages.
Edit: Do you think it is possible to apply something like this "getenv_command": ["/bin/bash", "--login", "-c", "env"],
to the settings for R-IDE? I had that in my rREPL settings file when that package was still viable for ST3.
It is the expected result, could you confirm it?
>>> import sys; sys.modules["R-IDE.ride.r"].R(script="cat(R.home('include'))")
'/Library/Frameworks/R.framework/Resources/include'
>>> import subprocess; subprocess.check_output(["R", "--slave", "-e", "cat(R.home('include'))"])
b'/Library/Frameworks/R.framework/Resources/include'
Try opening Sublime via Finder and via Terminal.
When launched from Terminal
>>> import sys; sys.modules["R-IDE.ride.r"].R(script="cat(R.home('include'))")
'[1] "'checkPackages' says: Ran package check and passed; loading required packages."
[1] "'syncPacks' says: 2 packages to add."
[1] "Note, custom functions are available: %nin%, cd, checkPackages, codebook, divisors, exit, f.countryyears, FillIn2, get_delay, ht, IHS, listcnames, lss, macopen, Mode, pwd, search.var.labels, sumstat, syncPacks, tscslag, WinsetCreator2"
.Rprofile load verified at Fri Oct 25 14:15:13 2019
/Library/Frameworks/R.framework/Resources/include
Goodbye at Fri Oct 25 14:15:13 2019 '
>>> import subprocess; subprocess.check_output(["R", "--slave", "-e", "cat(R.home('include'))"])
b'[1] "'checkPackages' says: Ran package check and passed; loading required packages."
[1] "'syncPacks' says: 2 packages to add."
[1] "Note, custom functions are available: %nin%, cd, checkPackages, codebook, divisors, exit, f.countryyears, FillIn2, get_delay, ht, IHS, listcnames, lss, macopen, Mode, pwd, search.var.labels, sumstat, syncPacks, tscslag, WinsetCreator2"
.Rprofile load verified at Fri Oct 25 14:24:21 2019
/Library/Frameworks/R.framework/Resources/include
Goodbye at Fri Oct 25 14:24:21 2019 '
Looks right to me.
When launched from Dock/Finder
>>> import sys; sys.modules["R-IDE.ride.r"].R(script="cat(R.home('include'))")
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/nrdavis/Library/Application Support/Sublime Text 3/Packages/R-IDE/ride/r.py", line 65, in R
stdout, stderr = p.communicate(input=stdin_text)
File "./python3.3/subprocess.py", line 920, in communicate
File "./python3.3/subprocess.py", line 1577, in _communicate
File "./python3.3/subprocess.py", line 848, in _translate_newlines
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 175: ordinal not in range(128)
>>> import subprocess; subprocess.check_output(["R", "--slave", "-e", "cat(R.home('include'))"])
b'[1] "'checkPackages' says: Ran package check and passed; loading required packages."
[1] "'syncPacks' says: 2 packages to add."
[1] "Note, custom functions are available: %nin%, FillIn2, IHS, Mode, WinsetCreator2, cd, checkPackages, codebook, divisors, exit, f.countryyears, get_delay, ht, listcnames, lss, macopen, pwd, search.var.labels, sumstat, syncPacks, tscslag"
.Rprofile load verified at Fri Oct 25 14:20:34 2019
/Library/Frameworks/R.framework/Resources/include
Goodbye at Fri Oct 25 14:20:34 2019 '
Oh, why you have these things?
checkPackages' says: Ran package check and passed; loading required package
If you are putting some code in .Rprofile
. Please make sure you check if the session is
interactive
if (interactive()) {
# whatever
}
Or it will break some scripts that parse the output of R.
It would appear as though I have been rather foolish - yes, it is an interactive session I have created with my .rprofile
code and this just happened to coincide with an R update I did. If I start ST3 from the Dock/Finder without my .rprofile
loading LSP initializes normally and full functionality returns to R-IDE.
I think this means that I need to reconsider the way I do my package checking. I do this because I regularly use different machines and wanted a way to ensure the same packages are installed locally on each one. Thank you for helping determine the issue.
A simple trick is just to check interactive()
.
I have the same problem, except LSP doesn't even manage to run R. This is macOS Catalina, R 4.0.1. Opening my first R file for a session gets me:
Could not start rlang
[Errno 2] No such file or directory: '/usr/local/bin/R --quiet --slave -e languageserver::run()'
Server will be disabled for this window
R is definitely located at /usr/local/bin. I have tried changing to just "R --quiet...", and also tried pointing it at the actual executable (/Library/Frameworks/R.framework/Resources/bin/R), but no love. Running Sublime Text from terminal vs launching via the dock makes no difference. Also tried launching from the terminal with sudo, also no difference. $LANG is en-US.UTF-8. Any ideas? I can't think of anything else to try...
Hi @mtalluto
In your LSP settings, if your command looks like the following for your rlang client:
"command": ["/usr/bin/R --slave --quiet -e languageserver::run()"]
Can you break it up into separate strings so it looks like:
"command": ["/usr/bin/R", "--slave", "--quiet", "-e languageserver::run()"]
Much like you, I had this error and took me a long time to workout the cause!! But the above edit fixed the issue.
Hello,
I installed R-IDE and LSP on windows, but LSP cannot start rlang (i guess) - where should I put path to R in settings?
Failed to start server Traceback (most recent call last): File "./python3.3/subprocess.py", line 1104, in _execute_child FileNotFoundError: [WinError 2] Systém nemůže nalézt uvedený soubor
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\1762\AppData\Local\sublime\Data\Installed Packages\LSP.sublime-package\plugin/core/process.py", line 28, in start_server startupinfo=si) File "./python3.3/subprocess.py", line 819, in init File "./python3.3/subprocess.py", line 1110, in _execute_child FileNotFoundError: [WinError 2]