DEV Community

Gabor Szabo
Gabor Szabo

Posted on • Originally published at code-maven.com

Setup local development environment for R-yaml

One of the participants in Open Source Development Course uses R for her research work. So we decided that in one of the meetings we'll try to explore how to set up local development environment for one of the R-based packages using Docker.

Disclaimer: none of the participants had any experience in contributing to open source projects in R so we might have totally misunderstood how one should set up an environment.

First we looked for a project to play with. Checked the r projects, then looked at the awesome-R list and found r-yaml. We thought a library dealing with YAML files will be simple to install and test.

One thing we noticed quite quickly is the the compile target was missing from the Makefile. That's however is a minor issue in the documentation.

Then we spent quite a lot of time figuring out why things are failing. After about an hour of failures we felt it would be better to open an issue. Within a few minutes, maybe half an hour we got a response that solved the problem.

So here is how one could create a local development environment in a Docker container:

Clone the repo

git clone git@github.com:vubiostat/r-yaml.git
cd r-yaml
Enter fullscreen mode Exit fullscreen mode

Start Docker container

Start a Docker container using an image based on R version 4.2.3 that was listed on Docker Hub.

Give the container a name "r-yaml" to make it easy to reuse it.

Designate the internal /opt folder as the workdir.

Map the current working directory to the internal /opt

I have not tried it, but I think MS Windows users will have to replace the -v$(pwd):/opt part by -v %cd%:/opt if using cmd or by -v ${PWD}:/opt if using PowerShell.

Run bash in the container.

docker run -it --name r-yaml --workdir /opt -v$(pwd):/opt r-base:4.2.3 bash
Enter fullscreen mode Exit fullscreen mode

Install RUnit

Inside the container install the R dependency.

Rscript -e 'install.packages("RUnit")'
Enter fullscreen mode Exit fullscreen mode

Install the external dependencies

apt-get update
apt-get install -y texlive-latex-base texlive-fonts-extra texlive-latex-recommended texlive-fonts-recommended
Enter fullscreen mode Exit fullscreen mode

Run the tests

make check
make test
Enter fullscreen mode Exit fullscreen mode

Exit from the container

exit
Enter fullscreen mode Exit fullscreen mode

This will also stop the container.

Restart the container

We can restart the stopped container:

docker container start -i r-yaml
Enter fullscreen mode Exit fullscreen mode

Remove the container

If we don't need the container any more we can remove it (after we exited and it was stopped).

docker rm r-yaml
Enter fullscreen mode Exit fullscreen mode

Clean the environment

sudo git clean -dxf
Enter fullscreen mode Exit fullscreen mode

This will print:

Removing build/
Enter fullscreen mode Exit fullscreen mode

Conclusion

I hope this description will help someone else setting up the environment. I'll also suggest to include this, or something similar in the README file of the project.

This certainly helped me and next time it will be easier to set up a development environment for an R-based project.

Top comments (2)

Collapse
 
silent_mobius profile image
Alex M. Schapelle

you should attach this to their repository

Collapse
 
szabgab profile image
Gabor Szabo

it's an issue already