Skip to content

r-devel/r-dev-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

R Dev Container

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

Open in GitHub Codespaces

A containerised development environment for editing and compiling the R source code. The environment contains the VSCode IDE and tools needed to compile R.

Getting started

You can run this environment on GitHub using codespaces

Codespaces

Click on the 'Open in GitHub Codespaces' button and then click the green 'Create Codespace' button. image

The codespace setup screen will then be shown. Starting the container may take a minute or so.

You will be taken to a VSCode editor within your browser.

image

Running R

Create a file in VS Code ending with a .R extension. You can create new files by clicking on the new file icon in VS Code. image

Open the file by clicking on the filename. You should see R:(not attached) in the bottom bar. image

Click on the R:(not attached) button to launch R in the terminal. You can then send code from the .R file to the R terminal by pressing cmd/ctrl + enter. image

R Contribution Workflow

Build Setup

  1. Environment Variables

    • We have environment variables for setting the paths for building R and storing the source code.

    • The path ENV variable for R Build and R Source code are BUILDDIR and TOP_SRCDIR respectively.

    • The environment variables are set in the codespace image and are available when the codespace starts.

      image

  2. svn checkout

    • The svn checkout cmd lets us create working of a repository with specific tag/branch.
    • Example:
       svn checkout https://svn.r-project.org/R/trunk/ "$TOP_SRCDIR"
    • Output : We get file structure something like this after checking out R source code from R svn repository. image
  3. cd to BUILDDIR

    • We need to change our directory to R build directory(BUILDDIR) to build and configure our R source code.
    • First we will create a directory using env var BUILDDIR.
      mkdir -p $BUILDDIR
    • Then we can change directory from root to $BUILDDIR one.
       cd $BUILDDIR
  4. configure source code

    • After we change directory to BUILDDIR we can configure and build R.

    • CMD

      "$TOP_SRCDIR/configure" --enable-R-shlib --without-recommended-packages
      make
      sudo make install
    • The configure cmd prepares for building R, creating files and folders inside the BUILDDIR directory.

    • Output : We get file structure something like this after using configure command.

      image

  5. After having built the current development version of R, we can now make changes in source code and make our contributions.

Contribution Workflow

  1. Example Contribution Workflow using DevContainer:

    • To start working in R we will click on R:(not attach) option which is in the bottom right of our R-dev codespace. It will open R terminal for us.

      image image

    • We can now run R commands. We will use the utils::askYesNo() function as an example image

      > askYesNo("Is this a good example?")
      Is this a good example? (Yes/no/cancel) Yes
      [1] TRUE
  2. Edit the source code of utils::askYesNo() to change the default options. The source code can be found in $TOP_SRCDIR/src/library/utils/R/askYesNo.R.

    Before edit: image

    prompts = getOption("askYesNo", gettext(c("Yes", "No", "Cancel"))),

    With edit (for example - change to whatever you like!): image

     prompts = getOption("askYesNo", gettext(c("Oh yeah!", "Don't think so", "Cancel"))),
  3. Re-build the utils package (we only need to re-build the part we have modified). We can rebuild the package by following simple steps

    • First we need to be inside $BUILDDIR, for that we can change directory to cd $BUILDDIR.

    • After that we can run cmd make and sudo make install in a series. image

      image

    • This will re-build any parts of R that have changed, in this case only re-building the utils package, then re-install R. If we open a new R terminal we will see our changes getting reflected.

  4. Check the edit has worked as expected by re-running the example code: image

    > askYesNo("Is this a good example?")
    Is this a good example? (Oh yeah!/don't think so/cancel) Oh yeah!
    [1] TRUE

Useful Links