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: Optionally allow packages from custom R environment #22219

Merged
merged 1 commit into from Jan 29, 2017

Conversation

Hodapp87
Copy link
Contributor

Motivation for this change

https://nixos.org/nixpkgs/manual/#r-packages contains a method for
setting up an R environment with a specific set of libraries, and it
creates an R wrapper which points R to those libraries.

The package RStudio relies on the standard R package, which then
cannot access any of the libraries specified in a custom R
environment. While one may easily use pkgs.rstudio.override to change
rstudio's R dependency to the custom R environment, this accomplishes
nothing because while RStudio runs the correct R wrapper it clears out
the environment variable R_LIBS_SITE - and so it is still unable to
use any of those packages.

Things done

In order to work around this problem, these changes allow the user to
optionally modify rstudio's wrapper to set environment variable
R_PROFILE_USER to an R script which sets R's .libPaths(..) to point to
the same libraries; that script is generated from R_LIBS_SITE in the R
wrapper.

By default, this change has no effect. If R is overridden to
something else, and if useRPackages is changed from its default of
false, then the change described above is made; for instance:

{
  packageOverrides = pkgs: let self = pkgs.pkgs; in
  rec {
    rEnv = pkgs.rWrapper.override {
      packages = with self.rPackages; [
        dplyr ggplot2 e1071 rpart reshape
      ];
    };
    rstudioEnv = pkgs.rstudio.override { R = rEnv; useRPackages = true; };
  };
}
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

https://nixos.org/nixpkgs/manual/#r-packages contains a method for
setting up an R environment with a specific set of libraries, and it
creates an R wrapper which points R to those libraries.

The package RStudio relies on the standard R package, which then
cannot access any of the libraries specified in a custom R
environment.  While one may easily use pkgs.rstudio.override to change
rstudio's R dependency to the custom R environment, this accomplishes
nothing because while RStudio runs the correct R wrapper it clears out
the environment variable R_LIBS_SITE - and so it is still unable to
use any of those packages.

In order to work around this problem, these changes allow the user to
optionally modify rstudio's wrapper to set environment variable
R_PROFILE_USER to an R script which sets R's .libPaths(..) to point to
the same libraries; that script is generated from R_LIBS_SITE in the R
wrapper.

By default, this change has no effect.  If R is overridden to
something else, and if useRPackages is changed from its default of
false, then the change described above is made; for instance:

{
  packageOverrides = pkgs: let self = pkgs.pkgs; in
  rec {
    rEnv = pkgs.rWrapper.override {
      packages = with self.rPackages; [
        dplyr ggplot2 e1071 rpart reshape
      ];
    };
    rstudioEnv = pkgs.rstudio.override { R = rEnv; useRPackages = true; };
  };
}
@mention-bot
Copy link

@Hodapp87, thanks for your PR! By analyzing the history of the files in this pull request, we identified @peti, @ehmry and @lverns to be potential reviewers.

@peti peti merged commit 456b9f8 into NixOS:master Jan 29, 2017
@knedlsepp
Copy link
Member

Sadly for me this leads to a recompilation of RStudio on every change to rEnv.

@Hodapp87
Copy link
Contributor Author

Hodapp87 commented Apr 5, 2017

Yeah, I have the same issue. I have been looking at using something more like how the R and rWrapper packages work. Since only an R startup file changes when the associated packages to RStudio change, it might make more sense to write this as a separate wrapper.

Hodapp87 added a commit to Hodapp87/nixpkgs that referenced this pull request May 1, 2017
This attempts to fix the issue described at
NixOS#22219 (comment).
Any change to the custom packages passed to RStudio causes this to
completely rebuild RStudio, which is completely unnecessary and also a
bit of a hindrance as it's a fairly slow build.

This rolls back most of that old PR, and instead implements something
more like rWrapper.  Existing configurations with the old useRPackages
will break.
@Hodapp87
Copy link
Contributor Author

Hodapp87 commented May 1, 2017

I've attempted to fix that issue in #25390

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

Successfully merging this pull request may close these issues.

None yet

4 participants