asdf-community / asdf-r

R plugin for the asdf version manager
https://github.com/asdf-vm/asdf
GNU General Public License v2.0
28 stars 5 forks source link

How to change .desktop entry on Linux to run R Studio with asdf R? #12

Open emstruong opened 11 months ago

emstruong commented 11 months ago

Provide environment information

OS:
Linux boomer 5.19.0-46-generic #47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 21 15:35:31 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

SHELL:
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

BASH VERSION:
5.1.16(1)-release

ASDF VERSION:
v0.12.0-816195d

ASDF INTERNAL VARIABLES:
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=.tool-versions
ASDF_DATA_DIR=/home/boomer/.asdf
ASDF_DIR=/home/boomer/.asdf
ASDF_CONFIG_FILE=/home/boomer/.asdfrc

ASDF INSTALLED PLUGINS:
r                            https://github.com/asdf-community/asdf-r.git master dda1807

To Reproduce

1) Install R Studio 2) Install R 4.3.1 using asdf and set r 4.3.1 as global 3) Try to open R studio through the desktop icon

Describe the Bug

R Studio doesn't start-up, presumably because it doesn't detect a version of R. Yet when R Studio is run in the terminal, it presumably detects that it should use the version of R based on asdf and runs

Expected Behaviour

R Studio should start using the version of R listed as global by asdf.

emstruong commented 11 months ago

Related to #7, the Arch Wiki, and Posit, the solution I found was to copy the rstudio.desktop file from /usr/share/applications/rstudio.desktop to ~/.local/share/applications/rstudio.desktop.

Then I modified the exec line to be like so

Exec=env RSTUDIO_WHICH_R=/home/boomer/.asdf/shims/R /usr/lib/rstudio/rstudio %F

where boomer is the username.

Then update your .desktop files by running this in shell update-desktop-database ~/.local/share/applications -v.

I haven't tested whether this respects the R version in particular directories/projects, but it works well enough for me.

Presumably, it might be also helpful to mimic #7 by setting R_HOME_DIR=$HOME/.asdf/installs/R/<version>/lib/R as an environment variable, but I don't know if one can set multiple environment variables in the rstudio.desktop file.

In my testing, adjusting ~/.profile the way Posit recommends didn't help

emstruong commented 5 months ago

Related to #7, the Arch Wiki, and Posit, the solution I found was to copy the rstudio.desktop file from /usr/share/applications/rstudio.desktop to ~/.local/share/applications/rstudio.desktop.

Then I modified the exec line to be like so

Exec=env RSTUDIO_WHICH_R=/home/boomer/.asdf/shims/R /usr/lib/rstudio/rstudio %F

where boomer is the username.

Then update your .desktop files by running this in shell update-desktop-database ~/.local/share/applications -v.

I haven't tested whether this respects the R version in particular directories/projects, but it works well enough for me.

Presumably, it might be also helpful to mimic #7 by setting R_HOME_DIR=$HOME/.asdf/installs/R/<version>/lib/R as an environment variable, but I don't know if one can set multiple environment variables in the rstudio.desktop file.

In my testing, adjusting ~/.profile the way Posit recommends didn't help

So far, I haven't been able to get R-Studio to run with the local version of R. If you start from the root of a R Studio Project directory, asdf loads the version of R listed in the .tool-versions file of that directory. Furthermore, it doesn't seem to appropriately change versions of R when projects are changed using that same instance of R Studio.

I imagine a fix would involve a change in R Studio's codebase in how it opens projects, but I'm not sure.