NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.1k stars 14.15k forks source link

rstudio's wrapper breaks loading of .Rprofile and use of R_USER_PROFILE #85840

Open unode opened 4 years ago

unode commented 4 years ago

Describe the bug A common mechanism to configure R is to create a .Rprofile file in the current directory, globally in ~/.Rprofile or setting the environment variable R_USER_PROFILE. The current rstudio wrapper makes use of the R_USER_PROFILE environment variable to inject additional paths via R's .libPaths(). However, once R_USER_PROFILE is defined in the environment, R no longer checks for either of the two .Rprofile locations mentioned (as can be read here). The fact that the wrapper uses R_USER_PROFILE also prevents the user from relying on it to customize the session.

To Reproduce Steps to reproduce the behavior:

  1. nix-env -iA rstudio
  2. create ~/.Rprofile containing cat("Hello from .Rprofile").
  3. If the file is sourced, the message should be printed in the R console

Expected behavior The file specified by the user in R_USER_PROFILE should be read or alternatively, .Rprofile files should be read in the above mentioned locations.

Additional context

  1. If the user has R_USER_PROFILE set in their environment, the wrapper should detect this and concatenate file specified by the user with the content of the fix_libs.R file (into a temporary file?) and set R_USER_PROFILE to this new location.
  2. If the user doesn't have R_USER_PROFILE set, the wrapper should replicate R's behaviour and source .Rprofile as described here.

Notify maintainers @ehmry @changlinli @ciil

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.28, NixOS, 19.09.git.4284573 (Loris)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.3`
 - channels(root): `"nixos-20.09pre217261.a2e06fc3423"`
 - nixpkgs: `/var/nixpkgs-channels/nixos`
stale[bot] commented 4 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

unode commented 4 years ago

This is still an issue

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

18kimn commented 1 year ago

I'd also like to know how to solve this! Thank you!

The relevant file appears to be https://github.com/NixOS/nixpkgs/blob/nixos-22.11/pkgs/development/r-modules/wrapper-rstudio.nix, and the environment variable (I believe?) is R_PROFILE_USER not R_PROFILE_USER

18kimn commented 1 year ago

Ah, anyone else who deals with this issue may be able to solve this by setting R_PROFILE instead of R_PROFILE_USER. Doesn't work for everyone, though

For instance, here's my flake.nix for one of my projects:


  outputs = { self, nixpkgs, utils } :
    utils.lib.eachDefaultSystem (system:
        let pkgs = import nixpkgs {
            inherit system; 
            overlays = [(self: super: {
                    customRstudio = super.rstudioWrapper.override {
                        packages = [super.rPackages.renv];
                    };
                })
            ];};
      in {
        devShell = (pkgs.buildFHSUserEnv {
                    name = "renv-compatible nix";
          targetPkgs = pkgs:
            (with pkgs; [
                            binutils
                            curl.dev
                            gcc
                            libgit2
                            /* Needed for various R dependencies */
                            libssh
                            libpng
                            gdal
                            geos
                            freetype.dev
                            proj.dev
                            libxml2.dev
                            openssl.dev
                            sqlite.dev
                            pandoc
                            zlib.dev
                            unixODBC
                            libmysqlclient.dev
                            udunits
                            pkg-config
                            /* Needed for basic R setup */ 
                            R
                            rPackages.renv
                            customRstudio
                            ]);
                            runScript = "bash";
                            profile = ''
                                export R_PROFILE=${builtins.toString ./.}/.Rprofile
                                '';
                    }).env;
      });
}