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

rstan and RStudio on linux with an R installation using subarchitectures #505

Open
BATurlach opened this issue Mar 11, 2018 · 2 comments
Open

Comments

@BATurlach
Copy link

Summary:

As indicated when raising issue #504, on my linux machine (Ubuntu 14.04.4 LTS), I compile R from source, and install both a 32 bit version and a 64 bit version; both as subarchitectures. To my surprise, I noticed that I cannot run stan() from the rstan package on my machine when I use RStudio.

Description:

The work-around to issue #504 that I am currently using is to create a symbolic link in R_HOME library/StanHeaders/libs/64/libStanHeaders.a to library/StanHeaders/libs/libStanHeaders.a. stan() works if R is started from the console, but not if it is started from RStudio. The error message I get is:

Error in get_makefile_txt() : 
  file /opt/R/R-3.4.3/lib/R/etc//Makeconf does not exist

Problem:

The error seems to be produced by lines 28-34 in the function get_makefile_txt() in rstan/R/makefile_op.R:

  WINDOWS <- .Platform$OS.type == "windows"
  rarch <- Sys.getenv("R_ARCH") # unix only
  if (WINDOWS && nzchar(.Platform$r_arch))
    rarch <- paste0("/", .Platform$r_arch)
  site <- file.path(R.home("etc"), rarch, "Makevars.site")

  sys_makeconf <- file.path(R.home("etc"), rarch, "Makeconf")

On my Linux machine, if I start R from the console, I get the following result:

> Sys.getenv("R_ARCH")
[1] "/64"

When I start R via RStudio, I get:

> Sys.getenv("R_ARCH")
[1] ""

By way of contrast, on a Windows machine, whether I start R directly or via RStudio, I always get:

> Sys.getenv("R_ARCH")
[1] "/x64"

Proposed Solution:

Looking at makeconf_path() in rstan/R/misc.R (lines 1377-1388), a solution might be to replace the above lines with:

  WINDOWS <- .Platform$OS.type == "windows"
  rarch <- .Platform$r_arch
  if (rarch = ''){
    site <- file.path(R.home("etc"), "Makevars.site")
    sys_makeconf <- file.path(R.home("etc"), "Makeconf")
  }else{
    site <- file.path(R.home("etc"), rarch, "Makevars.site")
    sys_makeconf <- file.path(R.home("etc"), rarch, "Makeconf")
  }

Not sure if the if() construct is needed as R does not seem to have problems with paths created by file.path() that contain // (in my limited experience).

I am not sure whether the logic of last_makefile() in rstan/R/makefile_op.R (lines 99-114) also needs revisiting.

RStan Version:

2.17.3

R Version:

R version 3.4.3 (2017-11-30)

> RStudio.Version()$version
[1] ‘1.1.423’

Operating System:

$ uname -a
Linux ECM-DTC-716 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.4 LTS
Release:	16.04
Codename:	xenial
@bgoodri
Copy link
Contributor

bgoodri commented Jun 13, 2018

Does this function work on your machine(s)?

get_makefile_txt <- function() {
  out <- system2(file.path(Sys.getenv("R_HOME"), "bin", "R"),
                 args = "CMD SHLIB --dry-run", stdout = TRUE)[2]
  makefiles <- strsplit(sub("SHLIB.*$", "", out), split = "-f ")[[1]][-1]
  makefiles <- gsub("'", "", makefiles)
  makefiles <- gsub("[[:space:]]*$", "", makefiles)
  makefiles <- makefiles[file.exists(makefiles)]
  do.call(c, lapply(makefiles, function(f) readLines(f, warn = FALSE))) 
}

@BATurlach
Copy link
Author

BATurlach commented Jun 15, 2018 via email

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

2 participants