Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open file created by R in an external program

Tags:

shell

logging

r

I want R to open a file that is created in my program. My code saves a log file to a variable called logFile using the following code.

logFile <- sprintf("../output/%s_%s_output%sof%s.log", str1, str2, str3, str4);

I tried to access the shell function by calling

shell('%s',logFile);

but I got an error that said

In shell("%s", toFile) : '%s' execution failed with error code 127

How can I get my program to open this file after it is finished writing to it?

like image 250
user1876508 Avatar asked Dec 04 '22 13:12

user1876508


2 Answers

How about?

browseURL('view.xlsx')
like image 145
Jerry T Avatar answered Dec 26 '22 05:12

Jerry T


Are you looking for something like this? It works nicely, at least on my Windows box.

## An example temp file
ff <- paste0(tempfile(), ".txt")
write.table(head(mtcars), file=ff)

## Open the file with the program associated with its file extension
system2("open", ff)
like image 34
Josh O'Brien Avatar answered Dec 26 '22 05:12

Josh O'Brien