R,将变量传递给系统命令 [英] R, passing variables to a system command
问题描述
使用 R,我希望创建一个二维码并将其嵌入到 Excel 电子表格(数百个代码和电子表格)中.显而易见的方法似乎是使用命令行创建二维码,并在 R 中使用系统"命令.有谁知道如何通过系统"命令传递 R 变量?Google 没有太大帮助,因为系统"有点笼统,?system 不包含任何此类示例.
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.
注意 - 我实际上使用的是数据矩阵而不是 QR 码,但是在 R 问题中使用术语数据矩阵"会导致严重破坏,所以让我们改用 QR 码.:-)
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.
推荐答案
假设我们有一个变量 x
我们想要传递给 dmtxwrite
,你可以传递它就像:
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))
或者使用paste
:
system(paste("dmtxwrite", x, "-o image.png"))
但在这种情况下我更喜欢 sprintf
.
but I prefer sprintf
in this case.
这篇关于R,将变量传递给系统命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!