在R中发送带有参数的系统命令

时间:2019-03-08 16:37:58

标签: r bash ess

我正在尝试在R中编写一个函数,该函数使我可以使用render() { const { checkValue, changeValue, label, meta: { touched, error } } = this.props; return ( <Content> <View> <View style={{ flexDirection: 'row' }}> <CheckBox checked={checkValue} onPress={changeValue} /> <Text style={styles.agreementsTextStyle}>{label}</Text> </View> {touched && error && <Text style={styles.errorText}>{error}</Text>} </View> </Content> ); }} 自动查看数据框。这个想法是,当我想查看数据时,该函数将编写一个临时的csv文件并使用R打开它。这是我的代码:

Libreoffice

并且代码有效。但是,我想使用view <- function(data) { FILE = "/home/spreadSheetView/temp.csv" write.csv(data, file = FILE, row.names = F) system(command = "export $(dbus-launch); \ export NSS_USE_SHARED_DB=ENABLED; \ libreoffice --calc /home/spreadSheetView/temp.csv") } Libreoffice之类的东西,而不是在$FILE中打开文件时使用绝对目录,并且最后一行代码如下:< / p>

${FILE}

不幸的是,程序无法通过这种方式找到文件。您能否建议是否有使用这种方法的方法?谢谢!

2 个答案:

答案 0 :(得分:2)

您可以使用

command = paste(
      "export $(dbus-launch); \
       export NSS_USE_SHARED_DB=ENABLED; \
       libreoffice --calc",
     FILE )
system(command)

答案 1 :(得分:1)

此社区Wiki答案取自先前存在于问题中的自我回答:


  

基于@CharlesDuffy的答案并进行了一些修订的代码,因为我无法使/bin/shexport一起工作。

view <- function(data) {
    FILE = "/home/spreadSheetView/temp.csv"
    write.csv(data, file = FILE, row.names = F)
    system2(command = "export",
        args = c("$(dbus-launch) NSS_USE_SHARED_DB=ENABLED; ",
                 "libreoffice --calc \"$1\" ",
                  FILE))
}