R: Difference between revisions
imported>Michael-J-Ward m Fix link to the R user guide in nixpkgs manual |
→Install an R-package from GitHub: Use current channel for search.nixos.org link Tags: Mobile edit Mobile web edit Advanced mobile edit |
||
(3 intermediate revisions by 3 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 77: | Line 101: | ||
== R with Flakes and nix-direnv== | == R with Flakes and nix-direnv== | ||
R and accompanying R-packages can be installed using a [ | R and accompanying R-packages can be installed using a [[Flakes | Flake]] and then managed/activated with [https://github.com/nix-community/nix-direnv nix-direnv] to create a reproducible development environment. After the initial setup of nix-direnv (instructions provided on the GitHub README), there is a [https://github.com/nix-community/nix-direnv/blob/master/templates/flake/flake.nix flake template] provided by the nix-direnv maintainers to get started. Run <code>nix flake new -t github:nix-community/nix-direnv .</code> to initialize the flake template in your current directory. This will create a `flake.nix` file that can be edited to setup the R-environment: | ||
<syntaxhighlight lang = "nix" > | <syntaxhighlight lang = "nix" > | ||
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. | ||
== A note on knitr == | == A note on knitr == | ||
Line 142: | Line 166: | ||
== Other Editors == | == Other Editors == | ||
'''with vim''' - [ | '''with vim''' - [[Nvim-r | nvim-r]] | ||
Line 166: | Line 190: | ||
However officer does work if installed using the conventional install.packages() which can be enabled as discussed in | However officer does work if installed using the conventional install.packages() which can be enabled as discussed in | ||
https://churchman.nl/tag/r/ | https://churchman.nl/tag/r/ | ||
[[Category:Languages]] |