loonline.blogg.se

Quickly get file path on r for mac
Quickly get file path on r for mac













quickly get file path on r for mac

If copy paste rstudioapi::getActiveDocumentContext() into the console, your context is your console and thus it will return an empty path. Note: It is important to run rstudioapi::getActiveDocumentContext() from your R Studio editor, because you want information about your R file. path: '~/Desktop/MyBlog/content/post/-changing-working-directories.Rmd' Among other things, this includes the path and the name of the R file you just ran. It returns a dataframe with information about your document context. Run rstudioapi::getActiveDocumentContext(). After reading and desperately trying things like this.dir <- dirname(ame(2)$ofile) But what if you changed the folder structure on your computer or your poor collegue tries to run your script after cloning your repo from git? I wanted to find a way to set the working directory in an R file automatically. This is error prone! Especially if you run your script on a regular basis for reports! And yes, you could copy paste your path. You can check your working directory with getwd() getwd()īut this only works for jobs you're starting manually and you have to remember setting the working directory.

QUICKLY GET FILE PATH ON R FOR MAC HOW TO

Session > Set Working Directory > To Source File Location R will print the code how to set your new working directory into the console setwd("~/Desktop/") Use the click interface of R Studio (I do not recommend that)















Quickly get file path on r for mac