[This article was first published on Data Driven Security, 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.
Sometimes you need to get to a command prompt from R, whether it’s to wrangle git
on the command line or do some package work. RStudio provides ways to do this from menus and hotkeys, but on OS X it sticks you in Terminal.app
. I’m an iTerm user—and, I really prefer being in that app vs the one Apple ships—so, I wrote a tiny function that will drop you into either the current working directory or a path you specify.
iterm <- function(directory=getwd()) { system(paste("osascript -e 'activate application "iTerm"' ", " -e 'tell application "System Events" to keystroke "t" using command down' ", sprintf(" -e 'tell application "iTerm" to tell session -1 of current terminal to write text "cd %s"'", directory))) }
It issues a three line AppleScript telling iTerm to
- activate (or launch)
- open a new tab
cd
to the desired location
Nothing earth shattering, but it saves a few mouse clicks and keystrokes and keeps me in the app I want to be in. It should be pretty straightforward to modify this for other operating systems.
To leave a comment for the author, please follow the link and comment on their blog: Data Driven Security.
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.