posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.75k stars 82 forks source link

linux compiled version of R not detected #3696

Closed rmflight closed 3 months ago

rmflight commented 4 months ago

Positron Version: 2024.06.1 build 27

Code - OSS Version: 1.90.0 Commit: a893e5b282612ccb2200102957ac38d3c14e5196 Date: 2024-06-26T01:22:29.024Z Electron: 29.4.0 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Linux x64 6.8.0-76060800daily20240311-generic

Steps to reproduce the issue:

  1. Compile and install R 4.3.0 from source on Linux (Pop!OS / Ubuntu 22.04)
  2. Install it via symlink at /usr/bin/R, /usr/bin/Rscript
  3. Create a new project, and select "R based project"

What did you expect to happen?

Installed R version would be discovered.

Were there any error messages in the output or Developer Tools console?

"No suitable interpreters found. Please install R 4.2.0 or later".

image

Note that this R version works fine for RStudio on Linux (set via an environment variable in .profile, I think). Also, I get like 12 different Python interpreters detected.

DavisVaughan commented 4 months ago

Sorry to hear that. We do look in /usr/bin/R for an R installation, so something is off here.

Can you please copy and paste in your full Positron R Extension output logs? You can get there by hitting Cmd + P to pull up the command palette, typing in Output: Show Output Channels..., and clicking on Positron R Extension. I'm looking for something like this:

2024-06-27 14:12:34.903 [info] Candidate R binary at /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R
2024-06-27 14:12:34.903 [info] R installation discovered: {
  "valid": true,
  "supported": true,
  "binpath": "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R",
  "homepath": "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources",
  "semVersion": {
    "options": {},
    "loose": false,
    "includePrerelease": false,
    "raw": "4.3.1",
    "major": 4,
    "minor": 3,
    "patch": 1,
    "prerelease": [],
    "build": [],
    "version": "4.3.1"
  },
  "version": "4.3.1",
  "arch": "arm64",
  "current": true,
  "orthogonal": true
}
2024-06-27 14:12:34.916 [info] Resolved R binary at /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R
rmflight commented 4 months ago

I was wondering how to get to that, after seeing some outputs in other issues.

2024-06-28 10:09:52.708 [info] Log level: Debug
2024-06-28 10:09:52.780 [info] Refreshing testthat status
2024-06-28 10:09:52.826 [info] Not working in an R package
2024-06-28 10:09:52.826 [info] Context key 'testthatIsConfigured' is 'false'
2024-06-28 10:09:52.826 [info] Context key 'testthatHasTests' is 'false'
2024-06-28 10:09:53.828 [info] Resolved R binary at /rmflight_stuff/software/R-4.3.0/bin/R
2024-06-28 10:09:53.828 [info] Candidate R binary at /rmflight_stuff/software/R-4.3.0/bin/R
2024-06-28 10:09:53.828 [info] Can't find DESCRIPTION for the utils package at "/rmflight_stuff/software/R-4.3.0"/library/utils/DESCRIPTION
2024-06-28 10:09:53.828 [info] Filtering out /rmflight_stuff/software/R-4.3.0/bin/R: invalid R installation.

That message is odd, because when I follow that path "/rmflight_stuff/software/R-4.3.0"/library/utils/DESCRIPTION, there is definitely a file there, with the R version encoded.

Is it something about the symlink, perhaps?

DavisVaughan commented 4 months ago

Could you try something for me?

/rmflight_stuff/software/R-4.3.0/bin/R should be a shell script, can you open it in a text editor for me?

Could you either paste in the entire contents of that shell script, or at least provide the line with R_HOME_DIR?

rmflight commented 4 months ago
#!/bin/bash
# Shell wrapper for R executable.

R_HOME_DIR="/rmflight_stuff/software/R-4.3.0"
if test "${R_HOME_DIR}" = "/usr/local/lib/R"; then
   case "linux-gnu" in
   linux*)
     run_arch=`uname -m`
     case "$run_arch" in
        x86_64|mips64|ppc64|powerpc64|sparc64|s390x)
          libnn=lib64
          libnn_fallback=lib
        ;;
        *)
          libnn=lib
          libnn_fallback=lib64
        ;;
     esac
     if [ -x "/usr/local/${libnn}/R/bin/exec/R" ]; then
        R_HOME_DIR="/usr/local/${libnn}/R"
     elif [ -x "/usr/local/${libnn_fallback}/R/bin/exec/R" ]; then
        R_HOME_DIR="/usr/local/${libnn_fallback}/R"
     ## else -- leave alone (might be a sub-arch)
     fi
     ;;
  esac
fi

if test -n "${R_HOME}" && \
   test "${R_HOME}" != "${R_HOME_DIR}"; then
  echo "WARNING: ignoring environment value of R_HOME"
fi
R_HOME="${R_HOME_DIR}"
export R_HOME
R_SHARE_DIR="${R_HOME_DIR}/share"
export R_SHARE_DIR
R_INCLUDE_DIR="${R_HOME_DIR}/include"
export R_INCLUDE_DIR
R_DOC_DIR="${R_HOME_DIR}/doc"
export R_DOC_DIR

# Since this script can be called recursively, we allow R_ARCH to
# be overridden from the environment.
# This script is shared by parallel installs, so nothing in it should
# depend on the sub-architecture except the default here.
: ${R_ARCH=}

usage="
Usage: R [options] [< infile] [> outfile]
   or: R CMD command [arguments]

Start R, a system for statistical computation and graphics, with the
specified options, or invoke an R tool via the 'R CMD' interface.

Options:
  -h, --help            Print short help message and exit
  --version             Print version info and exit
  --encoding=ENC        Specify encoding to be used for stdin
  --encoding ENC
  RHOME         Print path to R home directory and exit
  --save                Do save workspace at the end of the session
  --no-save             Don't save it
  --no-environ          Don't read the site and user environment files
  --no-site-file        Don't read the site-wide Rprofile
  --no-init-file        Don't read the user R profile
  --restore             Do restore previously saved objects at startup
  --no-restore-data     Don't restore previously saved objects
  --no-restore-history  Don't restore the R history file
  --no-restore          Don't restore anything
  --vanilla     Combine --no-save, --no-restore, --no-site-file,
            --no-init-file and --no-environ
  --no-readline         Don't use readline for command-line editing
  --max-ppsize=N        Set max size of protect stack to N
  --min-nsize=N         Set min number of fixed size obj's (\"cons cells\") to N
  --min-vsize=N         Set vector heap minimum to N bytes; '4M' = 4 MegaB
  -q, --quiet           Don't print startup message
  --silent              Same as --quiet
  -s, --no-echo         Make R run as quietly as possible
  --interactive         Force an interactive session
  --verbose             Print more information about progress
  -d, --debugger=NAME   Run R through debugger NAME
  --debugger-args=ARGS  Pass ARGS as arguments to the debugger
  -g TYPE, --gui=TYPE   Use TYPE as GUI; possible values are 'X11' (default)
            and 'Tk'.
  --arch=NAME       Specify a sub-architecture
  --args                Skip the rest of the command line
  -f FILE, --file=FILE  Take input from 'FILE'
  -e EXPR               Execute 'EXPR' and exit

FILE may contain spaces but not shell metacharacters.

Commands:
  BATCH         Run R in batch mode
  COMPILE       Compile files for use with R
  SHLIB         Build shared library for dynamic loading
  INSTALL       Install add-on packages
  REMOVE        Remove add-on packages
  build         Build add-on packages
  check         Check add-on packages
  LINK          Front-end for creating executable programs
  Rprof         Post-process R profiling files
  Rdconv        Convert Rd format to various other formats
  Rd2pdf        Convert Rd format to PDF
  Rd2txt        Convert Rd format to pretty text
  Stangle       Extract S/R code from Sweave documentation
  Sweave        Process Sweave documentation
  Rdiff         Diff R output ignoring headers etc
  config        Obtain configuration information about R
  javareconf        Update the Java configuration variables
  rtags                 Create Emacs-style tag files from C, R, and Rd files

Please use 'R CMD command --help' to obtain further information about
the usage of 'command'.

Options --arch, --no-environ, --no-init-file, --no-site-file and --vanilla
can be placed between R and CMD, to apply to R processes run by 'command'

Report bugs at <https://bugs.R-project.org>."

## some systems have a more portable sed, e.g. /usr/xpg4/bin/sed on Solaris,
## so make sure that is used.
SED=/usr/bin/sed
export SED

error () {
  echo "ERROR: $*" >&2
  exit 1
}

### Argument loop
args=
debugger=
debugger_args=
gui=
while test -n "${1}"; do
  case ${1} in
    RHOME|--print-home)
      echo "${R_HOME}"; exit 0 ;;
    CMD)
      shift;
      export R_ARCH
      . "${R_HOME}/etc${R_ARCH}/ldpaths"
      exec sh "${R_HOME}/bin/Rcmd" "${@}" ;;
    -g|--gui)
      if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
    gui="${2}"
        args="${args} ${1} ${2}"
    shift
      else
    error "option '${1}' requires an argument"
      fi
      ;;
    --gui=*)
      gui=`echo "${1}" | ${SED} -e 's/[^=]*=//'`
      args="${args} ${1}"
      ;;
    -d|--debugger)
      if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
    debugger="${2}"; shift
      else
    error "option '${1}' requires an argument"
      fi
      ;;
    --debugger=*)
      debugger=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
    --debugger-args=*)
      debugger_args=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
    -h|--help)
      echo "${usage}"; exit 0 ;;
    --args)
      break ;;
    --arch)
      if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
    R_ARCH="/${2}"
        shift
      else
        error "option '${1}' requires an argument"
      fi
      ## check sub-architecture here for a better error message
      if ! test -d ${R_HOME}/etc${R_ARCH}; then
        error "sub-architecture '${1}' is not installed"
      fi
      ;;
    --arch=*)
      r_arch=`echo "${1}" | ${SED} -e 's/[^=]*=//'`
      R_ARCH="/${r_arch}"
      ## check sub-architecture here for a better error message
      if ! test -d ${R_HOME}/etc${R_ARCH}; then
        error "sub-architecture '${r_arch}' is not installed"
      fi
      ;;
    -e)
      TAB=`printf "\t"`
      if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
    a=`(echo "${2}" && echo) | ${SED} -e 's/ /~+~/g' | \
          ${SED} -e :a -e N -e '$!ba' -e 's/\n/~n~/g' -e 's/~n~$//g' -e "s/$TAB/~t~/g"`
        shift
      else
    error "option '${1}' requires a non-empty argument"
      fi
      args="${args} -e $a"
      ;;
    -f)
      if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
    a=`echo "${2}" | ${SED} -e 's/ /~+~/g'`; shift
      else
    error "option '${1}' requires a filename argument"
      fi
      args="${args} -f $a"
      ;;
    --file=*)
      a=`echo "${1}" | ${SED} -e 's/[^=]*=//' | ${SED} -e 's/ /~+~/g'`
      args="${args} --file=$a"
      ;;
    --no-environ)
      R_ENVIRON=''
      export R_ENVIRON
      R_ENVIRON_USER=''
      export R_ENVIRON_USER
      args="${args} ${1}"
      ;;
    --no-site-file)
      R_PROFILE=''
      export R_PROFILE
      args="${args} ${1}"
      ;;
    --no-init-file)
      R_PROFILE_USER=''
      export R_PROFILE_USER
      args="${args} ${1}"
      ;;
    --vanilla)
      R_ENVIRON=''
      export R_ENVIRON
      R_ENVIRON_USER=''
      export R_ENVIRON_USER
      R_PROFILE=''
      export R_PROFILE
      R_PROFILE_USER=''
      export R_PROFILE_USER
      args="${args} ${1}"
      ;;
    *)
      args="${args} ${1}" ;;
  esac
  shift
done

. "${R_HOME}/etc${R_ARCH}/ldpaths"

R_binary="${R_HOME}/bin/exec${R_ARCH}/R"
export R_ARCH

case "${gui}" in
Tk|tk|X11|x11)
  ;;
"")
  ;;
*)
  error "unknown GUI ${gui}"
esac

## R_HOME may have moved, so check
if test -x "${R_HOME}"; then
  :
else
  error "R_HOME ('${R_HOME}') not found"
fi

## Startup
if test -z "${debugger}"; then
  exec "${R_binary}"  ${args} "${@}"
else
  ## Ideally, we would like the debugger to start R with additional
  ## ('inferior') arguments, but not all debuggers can do this.  We know
  ## about valgrind and some versions of GDB , and deal with these.
  ## Otherwise, to be on the safe side, we disregard non-debugger
  ## command line args.
  args_ok=no
  case "`${debugger} --version 2>/dev/null`" in
    "GNU gdb"*)
      if ${debugger} --help 2>/dev/null | \
          grep ' *--args' >/dev/null; then
    args_ok=yes
    debugger_args="${debugger_args} --args"
      fi
      ;;
    valgrind*)
      args_ok=yes
      ;;
  esac
  if test -n "${args}${*}" && test "${args_ok}" = no; then
    args=`expr "${args} ${*}" : " *\(.*\)"`
    echo "*** Further command line arguments ('${args}') disregarded"
    echo "*** (maybe use 'run ${args}' from *inside* ${debugger})"
    echo ""
    exec ${debugger} ${debugger_args} "${R_binary}"
  else
    exec ${debugger} ${debugger_args} "${R_binary}" ${args} "${@}"
  fi
fi

### Local Variables: ***
### mode: sh ***
### sh-indentation: 2 ***
### End: ***
DavisVaughan commented 4 months ago

If you remove the literal quotes " around the path in R_HOME_DIR="/rmflight_stuff/software/R-4.3.0" and then fully restart Positron, does it just magically work?

rmflight commented 4 months ago

Yes, yes it does.

2024-06-28 10:47:51.823 [info] Log level: Debug
2024-06-28 10:47:51.823 [info] Refreshing testthat status
2024-06-28 10:47:51.823 [info] Not working in an R package
2024-06-28 10:47:51.823 [info] Context key 'testthatIsConfigured' is 'false'
2024-06-28 10:47:51.823 [info] Context key 'testthatHasTests' is 'false'
2024-06-28 10:47:52.775 [info] Resolved R binary at /rmflight_stuff/software/R-4.3.0/bin/R
2024-06-28 10:47:52.776 [info] Candidate R binary at /rmflight_stuff/software/R-4.3.0/bin/R
2024-06-28 10:47:52.776 [info] R installation discovered: {
  "valid": true,
  "supported": true,
  "binpath": "/rmflight_stuff/software/R-4.3.0/bin/R",
  "homepath": "/rmflight_stuff/software/R-4.3.0",
  "semVersion": {
    "options": {},
    "loose": false,
    "includePrerelease": false,
    "raw": "4.3.0",
    "major": 4,
    "minor": 3,
    "patch": 0,
    "prerelease": [],
    "build": [],
    "version": "4.3.0"
  },
  "version": "4.3.0",
  "arch": "x86_64",
  "current": true,
  "orthogonal": true
}
2024-06-28 10:48:12.964 [info] Creating Positron R 4.3.0 language client (port 48149)
2024-06-28 10:48:12.964 [info] ARK (R 4.3.0) language client state changed uninitialized => starting
2024-06-28 10:48:13.019 [info] ARK (R 4.3.0) language client init successful
2024-06-28 10:48:13.019 [info] ARK (R 4.3.0) language client state changed starting => running
DavisVaughan commented 4 months ago

Nice! We will probably work around this by checking for quotes but we've never seen them on other Linux installations, or on macOS installations.

Do you happen to know if you did anything special that may have added them? It may just be an artifact of building from source, not sure.

rmflight commented 4 months ago

No, and I just checked my shell history, and I don't use quotes when I'm setting the installation path. Might be due to using zsh instead of bash?

My most recent installation, I didn't even set the install path, I think I literally just untarred it there and compiled it. So there was no even setting install path in the call to configure.

jonvanausdeln commented 4 months ago

@rmflight , there is a possible fix for this in the latest Positron. We are in the process of test/validating the fix, but please feel free to try it out and let us know if it works for you!

ronblum commented 3 months ago

Verified in Positron 2024.07.0-41 on Ubuntu 24.04 with R 4.3.0.

Tested by reproducing the final state:

  1. Install the precompiled R binaries provided by R, available at https://docs.posit.co/resources/install-r.html.
  2. Map the nested R and Rscript to /usr/bin/R and /usr/bin/Rscript.
  3. In /usr/bin/R, add quotes in the line beginning with R_HOME_DIR (likely line 4). But they're probably already there.

With this, the error was reproducible in Positron-2024.06.1-27.

Note that the interpreter was missing both from the New Project and Console options.