Reputation: 1289
I have generated a csv file in R and would like my script to open this file in excel so that someone with no knowledge of R can modify the data. (Ideally when I run the script excel opens and loads this file). What is the best way to accomplish this?
Upvotes: 2
Views: 2366
Reputation: 2974
The accepted answer does not work for me, although not sure why (Windows OS), and I keep having to search for this answer again and again- so here is the answer that works for future reference.
shell.exec(here::here("filename.csv"))
This should open any file with the default program. credit: answer lifted directly from Uwe Ligges outside of SO
(note: my use of the here::here()
function is just an easy way to create a complete filepath, referenced to your RStudio project directory)
Upvotes: 5
Reputation: 1344
The cmd
command to open an excel file is open excel file.xlsx
.
In R
you can run the command line using system
. So putting these together:
excel_file_with_path <- "C:/Users/myusername/Documents/file.xlsx"
command <- paste("open excel", excel_file_with_path)
system(command)
Upvotes: 3