R, passing variables to a system command

cran, r, shell, variables

Solution

Let's say we have the variable `x` that we want to pass on to `dmtxwrite`, you can pass it on like:

x = 10
system(sprintf("dmtxwrite %s -o image.png", x))

or alternatively using `paste`:

system(paste("dmtxwrite", x, "-o image.png"))

but I prefer `sprintf` in this case.

Problem

Using R, I am looking to create a QR code and embed it into an Excel spreadsheet (hundreds of codes and spreadsheets). The obvious way seems to be to create a QR code using the command line, and use the "system" command in R. Does anyone know how to pass R variables through the "system" command? Google is not too helpful as "system" is a bit generic, ?system does not contain any examples of this. Note - I am actually using data matrices rather than QR codes, but using the term "data matrix" in an R question will lead to havoc, so let's talk QR codes instead. :-) ``` system("dmtxwrite my_r_variable -o image.png") ``` fails, as do the variants I have tried with "paste". Any suggestions gratefully received.

Original source