R: Difference between revisions

imported>Jabranham
Show example of nix-shell usage
imported>Josephsdavid
Added template default.nix and shell.nix, as well as links to non-RStudio editors
Line 58: Line 58:


<code>rWrapper</code> simply replaces the R command in your path by a script that sets the environment variable <code>R_LIBS_SITE</code> and then runs R. [https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/r-modules/wrapper.nix]
<code>rWrapper</code> simply replaces the R command in your path by a script that sets the environment variable <code>R_LIBS_SITE</code> and then runs R. [https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/r-modules/wrapper.nix]
== With nix-shell ==
Below is an example of a nix-shell build to run R with knitr for R markdown:
'''default.nix'''
<syntaxhighlight lang = "nix">
let
  pkgs = import <nixpkgs> {};
  stdenv = pkgs.stdenv;
in with pkgs; {
  myProject = stdenv.mkDerivation {
    name = "Speedracer";
    version = "1";
    src = if pkgs.lib.inNixShell then null else nix;
    buildInputs =  [
      R
      rPackages.knitr
      rPackages.rmarkdown
      rPackages.knitr
    ];
  };
}
</syntaxhighlight>
== R with Lorri ==
An example of a '''shell.nix''' for usage with [https://github.com/target/lorri lorri] is shown below:
<syntaxhighlight lang = "nix">
let
  pkgs = import <nixpkgs> {};
in
  pkgs.mkShell {
    buildInputs = with pkgs; [
      R
      rPackages.rmarkdown
      rPackages.knitr
    ];
  }
</syntaxhighlight>
== Other Editors ==
'''with vim''' -  [https://nixos.wiki/wiki/Nvim-r nvim-r]
Note - if you are building an environment and plan on using nvim-r, it cannot also include rstudio, it will break your packages!
'''with emacs''' - [http://ess.r-project.org/ emacs speaks statistics]


== External Documentation ==
== External Documentation ==


* [https://nixos.org/nixpkgs/manual/#r-packages R user guide in nixpkgs manual]
* [https://nixos.org/nixpkgs/manual/#r-packages R user guide in nixpkgs manual]