0 votes
1 view
in R Programming by (5.3k points)

I am working out some tutorials in R. Each R code is contained in a specific folder. There are data files and other files in there. I want to open the .r file and source it such that I do not have to change the working directory in Rstudio as shown below:

enter image description here

Is there a way to specify my working directory automatically in R.

1 Answer

0 votes
by (25.3k points)

To set the working directory to the source file location, you can do the following:

To get the source file directory:

dirname(rstudioapi::getActiveDocumentContext()$path)

To set the working directory to source file directory:

setwd(dirname(rstudioapi::getActiveDocumentContext()$path))

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...