R: Difference between revisions
fix links |
Add an "Install an R package from source" section. |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 23: | Line 23: | ||
RStudio-with-my-packages = rstudioWrapper.override{ packages = with rPackages; [ ggplot2 dplyr xts ]; }; | RStudio-with-my-packages = rstudioWrapper.override{ packages = with rPackages; [ ggplot2 dplyr xts ]; }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Positron == | |||
Currently, the easiest way to use positron with nix is with mkShell:<syntaxhighlight lang="nix"> | |||
let | |||
pkgs = import <nixpkgs> { }; | |||
in | |||
pkgs.mkShell { | |||
packages = [ | |||
# Positron | |||
pkgs.positron-bin | |||
# R & packages. | |||
pkgs.R | |||
pkgs.rPackages.httr | |||
pkgs.rPackages.ggplot2 | |||
# Python, ipykernel & packages. | |||
# pkgs.python313 | |||
# pkgs.python313Packages.ipykernel # NOTE: Required for python. | |||
# pkgs.python313Packages.pandas | |||
# pkgs.python313Packages.requests | |||
]; | |||
} | |||
</syntaxhighlight>Other utilities like rWrapper are not compatible. | |||
== Jupyter Notebook == | == Jupyter Notebook == | ||
Line 134: | Line 158: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
You will need to obtain the `rev` and `sha256` for the package on github [https://search.nixos.org/packages? | You will need to obtain the `rev` and `sha256` for the package on github [https://search.nixos.org/packages?show=nix-prefetch-git&type=packages&query=nix-prefetch-git which can be found by using the `nix-prefetch-git` command line tool.] For the above example, running <code>nix-prefetch-git https://github.com/rstudio/rmarkdown</code> from a terminal will generate the information. You may need to manually specify other R-package/system dependencies for the specific package in the `propagatedBuildInputs`. This information can be found in the `DESCRIPTION` file of the R-package source directory. | ||
== Install an R package from source == | |||
If you need a specific version of a package or find one that is not available in Nixpkgs, you can use `rPackages.buildRPackage` to build from source. The example below builds S4Arrays from BioConductor.<syntaxhighlight lang="nix"> | |||
let | |||
pkgs = import <nixpkgs> { }; | |||
customPackage = pkgs.rPackages.buildRPackage { | |||
name = "S4Arrays"; | |||
src = pkgs.fetchurl { | |||
url = "https://www.bioconductor.org/packages/release/bioc/src/contrib/S4Arrays_1.8.1.tar.gz"; | |||
hash = "sha256-8f2oA0xgwI6CucXbMU1yJC4W6tiVMcDAk8D3Ur3zxw8="; | |||
}; | |||
buildInputs = with pkgs.rPackages; [ | |||
pkgs.R | |||
Matrix | |||
abind | |||
BiocGenerics | |||
S4Vectors | |||
IRanges | |||
crayon | |||
]; | |||
}; | |||
in | |||
pkgs.mkShell { | |||
packages = with pkgs.rPackages; [ | |||
pkgs.R | |||
Matrix | |||
abind | |||
BiocGenerics | |||
S4Vectors | |||
IRanges | |||
crayon | |||
customPackage # the package we built from source. | |||
]; | |||
} | |||
</syntaxhighlight> | |||
== A note on knitr == | == A note on knitr == | ||