R, passing variables to a system command

后端 未结 2 1941
醉梦人生
醉梦人生 2021-01-02 23:20

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

2条回答
  •  梦谈多话
    2021-01-02 23:56

    Also making use of base::system2 may be worth considering as system2 provides args argument that can be used for that purpose. In your example:

    my_r_variable <- "a"
    system2(
        'echo',
        args = c(my_r_variable, '-o image.png')
    )
    

    would return:

     a -o image.png
    

    which is equivalent to running echo in the terminal. You may also want to redirect output to text files:

    system2(
        'echo',
        args = c(my_r_variable, '-o image.png'),
        stdout = 'stdout.txt',
        stderr = 'stderr.txt'
    )
    

提交回复
热议问题