rbashess

Sending system command with arguments in R


I am trying to write a function in R that would allow me to automatically view a data frame using Libreoffice. The idea is that when I want to have a look at the data, the function will write a temporary csv file and open it with R. Here's the code that I have:

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")
}

And the code works. However, instead of using the absolute directory to the file when opening it in Libreoffice, I want to use something like $FILE or ${FILE}, and the last line of code will look like:

libreoffice --calc $FILE")

Sadly the program cannot find the file this way. Could you suggest if there are ways to use this methodology? Thanks!


Solution

  • You can use

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