Using rdlang In Your Docker Image

If you followed the instructions on the previous page, you've built the rdlang image, and you've created a directory on the host machine to share with Docker. Let's assume that you are using Windows for this example, and that you are making C:\Users\user1\dockershare available to the Docker image.

In directory C:\Users\user1\dockershare, create a file called "test.d". Add the following contents to the file and save it:

import rinsided;

void main() {
  evalRQ(`print("Hello from R")`);
  evalRQ(`print(getwd())`);
  evalRQ(`write.csv(1:10, file="foo.txt")`);
}

The first line tells R to print a message, the second line tells R to print the working directory, and the third line creates a text file "foo.txt" inside C:\Users\user1\dockershare.

If the image is not running, start it by entering into the Docker terminal

docker run --rm -ti -u docker -v //c/Users/user1/dockershare:/home/docker -w /home/docker rdlang

You can build and run the test program by running the following command inside the image:

rdlang test

You should see the call to DMD followed by the output:

docker@94819c9276c4:~$ rdlang test
dmd test.d /opt/rdlang/rinsided.d /opt/rdlang/rdlang/gretl.d /opt/rdlang/r
dlang/matrix.d /opt/rdlang/rdlang/r.d /opt/rdlang/rdlang/random.d /opt/rdl
ang/rdlang/reg.d /opt/rdlang/rdlang/vector.d /opt/rdlang/rdlang/optim.d  -
L/opt/rdlang/librinsided.so -L/usr/local/lib/R/site-library/RInside/lib/li
bRInside.so 


[1] "Hello from R"
[1] "/home/docker"

You should also see a new file "foo.txt" inside C:\Users\user1\dockershare.

For basic usage, where you have a single .d source file, that is all you have to do. If you want to call functions in other source files, you can do that by creating a dmdadd.txt file as described here.