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

RStudio will not run with R installed in location other than /usr/bin #13184

Closed
4 tasks done
abalter opened this issue May 31, 2023 · 25 comments
Closed
4 tasks done

RStudio will not run with R installed in location other than /usr/bin #13184

abalter opened this issue May 31, 2023 · 25 comments
Assignees
Labels
bug info needed Additional information requested—reprex, steps, open question, etc. startup Problems with starting up, installation, etc.

Comments

@abalter
Copy link

abalter commented May 31, 2023

System details

RStudio Edition : Desktop
RStudio Version :  Multiple
OS Version      :  Ubuntu 22.04
R Version       :  4.2.3

Steps to reproduce the problem

which R
# /home/balter/micromamba/bin/R
find micromamba -type f -name "libR.so"
# micromamba/lib/R/lib/libR.so
wget https://download1.rstudio.org/electron/jammy/amd64/rstudio-2023.03.1-446-amd64.deb
sudo gdebi rstudio-2023.03.1-446-amd64.deb

Describe the problem in detail

I have tried downloading and installing multiple versions of rstudio desktop including the current stable (as shown above) and others from the dailies. None of them will open. I get an error about not being able to find libR.so.

This is the same behavior as in #12508. Furthermore, if I google this problem of rstudio not being able to find libR.so it seems to be very common.

I have included my session startup failure report at the bottom.

I have tried setting R library paths with a .Renviron file and with not using one.

Describe the behavior you expected

RStudio would start.

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

R Session Startup Failure Report

RStudio Version

RStudio 2023.03.1+446 "Cherry Blossom " (6e31ffc, 2023-05-09) for Ubuntu Jammy

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) rstudio/2023.03.1+446 Chrome/108.0.5359.179 Electron/22.0.3 Safari/537.36

Error message

[No error available]

Process Output

The R session exited with code 127.

Error output:

/usr/lib/rstudio/resources/app/bin/rsession: error while loading shared libraries: libR.so: cannot open shared object file: No such file or directory

Standard output:

[No output emitted]

Logs

/home/balter/.local/share/rstudio/log/rsession-balter.log

]; OCCURRED AT rstudio::core::Error rstudio::r::exec::evaluateString(const string&, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::EvalFlags) src/cpp/r/RExec.cpp:375; LOGGED FROM: int rstudio::r::session::RReadConsole(const char*, CONSOLE_BUFFER_CHAR*, int, int) src/cpp/r/session/RStdCallbacks.cpp:299
2023-05-31T15:26:09.700096Z [rsession-balter] ERROR R SUICIDE: 2023-05-31T15:26:09.699990Z [rsession-balter] ERROR r error 4 (Error in dyn.load(file, DLLpath = DLLpath, ...) : |||  unable to load shared object '/home/balter/micromamba/lib/R/library/utils/libs/utils.so':|||  /home/balter/micromamba/lib/R/library/utils/libs/utils.so: undefined symbol: R_maphash|||) [errormsg: Error in dyn.load(file, DLLpath = DLLpath, ...) : |||  unable to load shared object '/home/balter/micromamba/lib/R/library/utils/libs/utils.so':|||  /home/balter/micromamba/lib/R/library/utils/libs/utils.so: undefined symbol: R_maphash|||]; OCCURRED AT rstudio::core::Error rstudio::r::exec::evaluateString(const string&, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::EvalFlags) src/cpp/r/RExec.cpp:375; LOGGED FROM: void {anonymous}::rSuicide(const string&) src/cpp/session/SessionMain.cpp:1242
2023-05-31T15:26:09.700096Z [rsession-balter] ERROR R SUICIDE: 2023-05-31T15:26:09.699990Z [rsession-balter] ERROR r error 4 (Error in dyn.load(file, DLLpath = DLLpath, ...) : |||  unable to load shared object '/home/balter/micromamba/lib/R/library/utils/libs/utils.so':|||  /home/balter/micromamba/lib/R/library/utils/libs/utils.so: undefined symbol: R_maphash|||) [errormsg: Error in dyn.load(file, DLLpath = DLLpath, ...) : |||  unable to load shared object '/home/balter/micromamba/lib/R/library/utils/libs/utils.so':|||  /home/balter/micromamba/lib/R/library/utils/libs/utils.so: undefined symbol: R_maphash|||]; OCCURRED AT rstudio::core::Error rstudio::r::exec::evaluateString(const string&, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::EvalFlags) src/cpp/r/RExec.cpp:375; LOGGED FROM: void {anonymous}::rSuicide(const string&) src/cpp/session/SessionMain.cpp:1242

@abalter abalter added bug new New incoming issues, ready for initial review. labels May 31, 2023
@abalter abalter changed the title RStudio will not run with R installed RStudio will not run with R installed in location other than /usr/bin May 31, 2023
@ronblum
Copy link
Contributor

ronblum commented Jun 8, 2023

@abalter Thank you for raising this issue!

@timtmok Is this limitation expected?

@ronblum ronblum removed the new New incoming issues, ready for initial review. label Jun 8, 2023
@abalter
Copy link
Author

abalter commented Jun 8, 2023

Also #9893, #11069

@timtmok
Copy link
Contributor

timtmok commented Jun 8, 2023

I think it is an issue with the path verification for libR.so. R.home() is called to build the path to libR.so. R home seems to return the path to the executable so something like /usr/bin/R is joined to the lib name to produce /usr/bin/R/libR.so, which is invalid.

@abalter
Copy link
Author

abalter commented Jun 8, 2023

Could it simply check the user's native environment?

@timtmok
Copy link
Contributor

timtmok commented Jun 8, 2023

I think this is just an incorrect file path that is created. It likely slipped past testing because the customized install location scenario wasn't tested.

Using R.home() is likely correct but Linux returns the executable. MacOS returns the directory, which would build the correct path. It might have been an incorrect assumption that R.home() on Linux would return a directory.

@abalter
Copy link
Author

abalter commented Jun 8, 2023

Do we need to find the place in the code where that is happening, or do you think RStudio will do it? @cm421 @MariaSemple

@kevinushey
Copy link
Contributor

Using R.home() is likely correct but Linux returns the executable.

I don't think that's true? A regular R installation on my Ubuntu VM has:

> R.home()
[1] "/usr/lib/R"

And indeed that's a directory where R's components have been installed:

root@96722b73f316:/usr/lib/R# ll
total 40
drwxr-xr-x  8 root root 4096 Dec  4  2022 ./
drwxr-xr-x  1 root root 4096 Dec  4  2022 ../
lrwxrwxrwx  1 root root   33 Feb  8  2022 COPYING -> ../../share/common-licenses/GPL-2
-rw-r--r--  1 root root   46 Feb  8  2022 SVN-REVISION
drwxr-xr-x  3 root root 4096 Dec  4  2022 bin/
drwxr-xr-x  2 root root 4096 Dec  4  2022 etc/
drwxr-xr-x  2 root root 4096 Dec  4  2022 lib/
drwxr-xr-x 32 root root 4096 Dec  4  2022 library/
drwxr-xr-x  2 root root 4096 Dec  4  2022 modules/
drwxr-xr-x  2 root root 4096 Feb  8  2022 site-library/

and so libR.so is found here:

root@96722b73f316:/usr/lib/R/lib# ll
total 3300
drwxr-xr-x 2 root root    4096 Dec  4  2022 ./
drwxr-xr-x 8 root root    4096 Dec  4  2022 ../
-rw-r--r-- 1 root root 3368224 Feb  8  2022 libR.so

but there is also a symlink at /usr/lib/libR.so.

@abalter's error logs have:

2023-05-31T15:26:09.700096Z [rsession-balter] ERROR R SUICIDE: 2023-05-31T15:26:09.699990Z [rsession-balter] ERROR r error 4 (Error in dyn.load(file, DLLpath = DLLpath, ...) : ||| unable to load shared object '/home/balter/micromamba/lib/R/library/utils/libs/utils.so':||| /home/balter/micromamba/lib/R/library/utils/libs/utils.so: undefined symbol: R_maphash|||) [errormsg: Error in dyn.load(file, DLLpath = DLLpath, ...) : ||| unable to load shared object '/home/balter/micromamba/lib/R/library/utils/libs/utils.so':||| /home/balter/micromamba/lib/R/library/utils/libs/utils.so: undefined symbol: R_maphash|||]; OCCURRED AT rstudio::core::Error rstudio::r::exec::evaluateString(const string&, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::EvalFlags) src/cpp/r/RExec.cpp:375; LOGGED FROM: void {anonymous}::rSuicide(const string&) src/cpp/session/SessionMain.cpp:1242

which makes me think this is an issue with the R (micromamba?) installation.

@abalter, what does R.home() report in your R installation?

@abalter
Copy link
Author

abalter commented Jun 9, 2023

(base) balter@expiyes:~$ Rscript -e "print(R.home())"
[1] "/home/balter/micromamba/lib/R"

@kevinushey
Copy link
Contributor

That looks correct to me; we'll probably have to investigate further to understand what's going wrong.

@timtmok
Copy link
Contributor

timtmok commented Jun 9, 2023

Ah yes, R.home() seems to give me a correct path to R as well /usr/lib/R.

@antczakp
Copy link

antczakp commented Jun 16, 2023

Hi all, so we are having similar issues with rsutdio > 2022.04 - any R version that is installed in a conda environment and that is called fine in the terminal does not get started up by rstudio. So I looked at the 2023.06 logs and what I got was the following:

2023-06-12T12:31:46.721Z DEBUG instance lock: true, project: , file: false
2023-06-12T12:31:46.722Z DEBUG net-ipc: creating new message server; socket=/data/user/pantczak/.local/share/rstudio/rstudio.socket
2023-06-12T12:31:46.724Z DEBUG No rPath found, scanning for R
2023-06-12T12:31:46.724Z DEBUG Using /data/user/pantczak/my-envs/R4.2.2/bin/R (found by RSTUDIO_WHICH_R environment variable)
2023-06-12T12:31:46.724Z DEBUG Done choosing R
2023-06-12T12:31:46.724Z DEBUG Preparing environment using R: /data/user/pantczak/my-envs/R4.2.2/bin/R
2023-06-12T12:31:46.724Z DEBUG Querying information about R executable at path: /data/user/pantczak/my-envs/R4.2.2/bin/R
2023-06-12T12:31:46.892Z DEBUG stdout:
4.2.2;/data/user/pantczak/my-envs/R4.2.2/lib/R;/data/user/pantczak/my-envs/R4.2.2/lib/R/doc;/data/user/pantczak/my-envs/R4.2.2/lib/R/include;/data/user/pan>
2023-06-12T12:31:46.893Z DEBUG stderr: [no stderr produced]
2023-06-12T12:31:46.893Z DEBUG status: 0 [success]
2023-06-12T12:31:46.895Z DEBUG Launching rsession: /usr/lib/rstudio/resources/app/bin/rsession --config-file none --program-mode desktop --www-port 46691 ->
2023-06-12T12:31:46.895Z DEBUG R_HOME: /data/user/pantczak/my-envs/R4.2.2/lib/R
2023-06-12T12:31:46.895Z DEBUG RS_INITIAL_PROJECT:
2023-06-12T12:31:46.895Z DEBUG RS_LOG_LEVEL:
2023-06-12T12:31:46.964Z DEBUG Setting base URL: http://127.0.0.1:46691
2023-06-12T12:31:46.966Z DEBUG 'frame-created': [<event>, <object>]
2023-06-12T12:31:46.966Z DEBUG 'did-start-loading': [<event>]
2023-06-12T12:31:46.966Z DEBUG 'did-start-navigation': [<event>, "http://127.0.0.1:46691/", false, true, 4, 1]
2023-06-12T12:31:46.967Z DEBUG net-ipc: 11103 taking over as primary instance

It seems everything is being selected correctly but the rsession that is launched does not have a config file (?) and that seems to cause it to start the standard R version installed instead. Any ideas?

@abalter
Copy link
Author

abalter commented Jun 17, 2023

I would like to note that

To manage expectations for the many RStudio users suffering from the libR.so problem, could one of the RStudio developers please comment on where fixing this sits in the development priority list?

I don't know how many of the developers I tagged in this post actually work for Posit, as in actually get paid for their work. But this is a pretty significant bug IMO, and I'm eager to see it fixed.

@antczakp
Copy link

Just for completeness I just checked the daily rstudio build and that cannot deal with multiple Rs properly either.

@tcgriffith
Copy link

I had the same problem with rstudio 2023.06.0 build 421 and conda installed R 4.2.3.

my temporary hack is to create soft links for all .so libraries under /usr/lib/ . with

for i in ~/miniconda3/envs/renv43/lib/*.so*;do ln -rs $i /usr/lib/ ;done

@ronblum ronblum self-assigned this Jul 5, 2023
@ronblum ronblum modified the milestones: Backlog-1, Backlog-2 Jul 5, 2023
@mfansler
Copy link
Contributor

Could this please be moved to a proper release milestone? Linux users of Conda R have not had a compatible release of RStudio in over a year now.

@jgutman jgutman added the triage label Oct 3, 2023
@ronblum ronblum removed the triage label Oct 5, 2023
@ronblum ronblum removed this from the Backlog-2 milestone Oct 5, 2023
@ronblum ronblum added startup Problems with starting up, installation, etc. and removed qa repro labels Oct 5, 2023
@sharon-wang sharon-wang added this to the Chocolate Cosmos milestone Oct 11, 2023
@jthomasmock
Copy link
Contributor

We're planning to tackle this in the first RStudio release of 2024. Thanks all for the patience!

@abalter
Copy link
Author

abalter commented Oct 12, 2023

Thanks for the update!

@simon7073
Copy link

simon7073 commented Nov 29, 2023

Perhaps rstudio-server cannot access some files in the virtual environment.

An alternative:
Look at the user group for libR.so and add rstudio-server to it

$ ls -l /tools/miniconda3/envs/r-base/lib/R/lib/libR.so
-rwxrwxr-x. 2 test001 test001 
$ sudo usermod -a -G test001 rstudio-server
$ sudo rstudio-server verify-installation
$ sudo rstudio-server start

And edit file /tools/miniconda3/envs/r-base/lib/R/etc/Rprofile.site

Sys.setenv("PATH"="/tools/miniconda3/envs/r-base/bin:/home/test001/.local/bin:/home/test001/bin:/tools/miniconda3/condabin:/home/test001/.local/bin:/home/test001/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin")

@kevinushey
Copy link
Contributor

Note: Conda includes a patch to their R installation that ensures LD_LIBRARY_PATH is never appropriately set. Its contents are:

$ cat ldpaths 
# https://github.com/conda/conda/issues/1679:
#  Internally R_system() calls system() which
# uses /bin/sh to launch various programs. If
# /bin/sh is called with LD_LIBRARY_PATH that
# loads condas shared libraries things break.
#  It may be that not setting LD_LIBRARY_PATH
# causes other things to break, in which case
# R_system() will need to be modified so that
# it calls execve() with an environment which
# has these modifications to LD_LIBRARY_PATH
# removed which may be tricky to orchestrate
if [ "$(uname -s)" = "Linux" ]; then
  return 0
fi
: ${JAVA_HOME=/usr/lib/jvm/java-17-openjdk-arm64}
: ${R_JAVA_LD_LIBRARY_PATH=/home/conda/feedstock_root/build_artifacts/r-base-split_1709218192803/_build_env/lib/jvm/lib/server}
if test -n "/home/kevin/micromamba/lib"; then
: ${R_LD_LIBRARY_PATH=${R_HOME}/lib:/home/kevin/micromamba/lib}
else
: ${R_LD_LIBRARY_PATH=${R_HOME}/lib}
fi
if test -n "${R_JAVA_LD_LIBRARY_PATH}"; then
  R_LD_LIBRARY_PATH="${R_LD_LIBRARY_PATH}:${R_JAVA_LD_LIBRARY_PATH}"
fi
## This is DYLD_FALLBACK_LIBRARY_PATH on Darwin (macOS) and
## LD_LIBRARY_PATH elsewhere.
## However, on macOS >=10.11 (if SIP is enabled, the default), the
## environment value will not be passed to a script such as R.sh, so
## would not seen here.
if test -z "${LD_LIBRARY_PATH}"; then
  LD_LIBRARY_PATH="${R_LD_LIBRARY_PATH}"
else
  LD_LIBRARY_PATH="${R_LD_LIBRARY_PATH}:${LD_LIBRARY_PATH}"
fi
export LD_LIBRARY_PATH

See:

conda/conda#1679

This causes problems for RStudio, since normally we'd be able to find the requested libraries using that script. RStudio starts fine if I remove that preamble, so to make this work we'll have to work around Anaconda's patch.

@ronblum
Copy link
Contributor

ronblum commented Mar 15, 2024

RStudio Server: Verified in 2024.04.0-daily+593 on Ubuntu 22.04.

  • Before the fix, RStudio Server failed to run. In the log file:

2024-03-15T20:20:14.626362Z [rserver] ERROR Path to R not specified, and no module binary specified; Invalid R module (); LOGGED FROM: int main(int, char* const*) src/cpp/server/ServerMain.cpp:866

  • Tested by moving to another directory in the path, to /usr/local/games/, an unlikely place for anyone or any software to go looking for R. With the fix, this is a legitimate location for R.

RStudio Desktop: I'm not able to reproduce the problem in both Ubuntu 22.04 and Red Hat 9, so I can't claim that it's working because it's fixed. Would any of y'all be willing to try out one of the latest RStudio 2024.04.0 Chocolate Cosmos dailies and check if the problem is fixed? Please note that these are meant for testing and development only, not production.

@ronblum ronblum added the info needed Additional information requested—reprex, steps, open question, etc. label Mar 15, 2024
@ronblum ronblum assigned kevinushey and unassigned kevinushey and ronblum Mar 15, 2024
@gtritchie
Copy link
Member

gtritchie commented Mar 18, 2024

I was able to repro the problem on Ubuntu 22 as follows:

error-starting-r

Then, verified the fix:

@nivertech
Copy link

nivertech commented Mar 23, 2024

On Ubuntu 22.04.1:

$ uname -a
Linux HOSTNAME 6.5.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 12 10:22:43 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

R installed globally via asdf:

$ R

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> R.home()
[1] "/home/USER/.asdf/installs/r/4.3.1/lib/R"
> 
$ R

R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> R.home()
[1] "/home/USER/.asdf/installs/r/4.3.3/lib/R"
> 
Save workspace image? [y/n/c]: n

@kevinushey
Copy link
Contributor

kevinushey commented Mar 23, 2024

Did you configure R with --enable-R-shlib? What is the output of:

head $(R RHOME)/etc/Makeconf

?

@nivertech
Copy link

@kevinushey I re-installed RStudio with --enable-R-shlib as explained here [1] and it works now. Thanks!

  1. https://github.com/asdf-community/asdf-r?tab=readme-ov-file#building-r-shared-library

@kevinushey
Copy link
Contributor

Awesome, glad to hear that resolved the issue -- thanks for reporting back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug info needed Additional information requested—reprex, steps, open question, etc. startup Problems with starting up, installation, etc.
Projects
None yet
Development

No branches or pull requests