Open a File Folder in R
[This article was first published on Steve's Data Tips and Tricks, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Inroduction
When writing a function, it is possible that you may want to ask the user where they want the data stored and if they want to open the file folder after the download has taken place. Well we can do this in R by invoking the shell.exec()
command where we use a variable like f_path
that is the path to the folder. We are going to go over a super simple example.
Function
Here is the function:
shell.exec(file)
Here are the arguments.
file
– file, directory or URL to be opened.
Now let’s go over a simple example
Example
Here we go.
# Create a temporary file to store the zip file f_path <- utils::choose.dir() # Open file folder? if (.open_folder){ shell.exec(f_path) }
If in our function creation we make a variable .open_folder
and set it equal to TRUE then the if statement will execute and shell.exec(f_path)
will open the specified path set by utils::choose.dir()
Voila!
To leave a comment for the author, please follow the link and comment on their blog: Steve's Data Tips and Tricks.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.