stan-dev / stan-dev/rstan

rstan and RStudio on linux with an R installation using subarchitectures

Open
#505 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in rstan/R/makefile_op.R, especially get_makefile_txt() and last_makefile(), and compare their path handling with makeconf_path() in rstan/R/misc.R. Reproduce the issue under RStudio with R_ARCH unset and with R subarchitectures, then verify that stan() locates the appropriate Makeconf and related files.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.