Skip to content

alexg9010/vscode_guix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using R via vscode and guix

Prerequisites:

Idea

For this setup we are going to use vscode as our IDE and Guix to manage project-related software-environments. We are interfacing the two using a vscode extension to allow integrating direnv, which can update Environment Variables in our shell on a project-by-project basis.

Install Extensions

Alt text

Alt text

Setup

Save vscode-r.scm as a baseline manifest for R that allows smooth integration with vscode:

(specifications->manifest
  (list "r-minimal"

        ;; base packages
        "bash-minimal"
        "glibc-locales"
        "nss-certs"

        ;; Common command line tools lest the container is too empty.
        "coreutils"
        "grep"
        "which"
        "wget"
        "sed"
        "git"
        "fd"
        "ripgrep"
        "direnv"

        ;; R markdown tools
        "pandoc"

        ;; Toolchain and common libraries for "install.packages"
        "gcc-toolchain@10"
        "gfortran-toolchain"
        "gawk"
        "tar"
        "gzip"
        "unzip"
        "make"
        "cmake"
        "pkg-config"
        "cairo"
        "libxt"
        "openssl"
        "curl"
        "zlib"

        ;; vscode dependencies
        "r-lintr"
        "r-styler"
        "r-languageserver"
        "r-httpgd"

        ))

Save any additional packages in pkgs.scm:

(specifications->manifest
  (list "r-dplyr"
        "r-readr"
        "r-tidyr"
        "r-purrr"
        "r-forcats"
        ))

Save a minimal .envrc configuration file:

## this is required to create and load a guix profile in the current directory
GUIX_PROFILE="$PWD/.guix-profile"
eval $(guix package -p "$GUIX_PROFILE"  -m vscode-r.scm -m pkgs.scm)
eval $(guix package -p "$GUIX_PROFILE" --search-paths)

## this is required to have guix and common tools (less, man etc.) in PATH 
PATH="/bin:/usr/bin:/gnu/remote/bin:$PATH" 

Reload the vscode workspace. There should be a popup asking you to allow the loading of the .envrc file. Click `Allow``

Alt text

Another popup will ask you to restart extensions. Click Restart

Alt text

Now, on the left side of the status bar you should see the following:

Alt text

which indicates that the .envrc file has been loaded and some environment variables are changed.

You may also notice that a guix profile has been created in the current directory.

Alt text

Now we can try using R in vscode. Please open the test.R file in the test folder and run the lines using cmd/ctrl+enter.

Click here to see the output:

Alt text

Hah! The ggplot2 package has been missing.

Lets install it by adding r-ggplot2 to the pkgs.scm file.

Wait until direnv has updated the environment variables and retry the same command.

Show me the output:

Uh! Still does not work.

Yes, you first have to restart the R session, because the absolute guix profile has changed.

If you want to install packages without reloading the session, you may use the guix.install R package (guix name: r-guix-install). You can install packages into the currently loaded profile by using

guix.install("r-ggplot2", profile = Sys.getenv("GUIX_PROFILE"))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published