oreobad.blogg.se

R get file path
R get file path




r get file path
  1. #R GET FILE PATH HOW TO#
  2. #R GET FILE PATH FULL#

nimode <- sub("-file=", "", commandArgs(trailingOnly = FALSE))ĬommandArgs(trailingOnly = FALSE) = "-interactive", If you are using RStudio to run the R script in interactive mode and sometimes in non-interactive mode, you can detect that and return the necessary path. Get the path to the current R script depending on the running mode print(sub("-file=", "", commandArgs(trailingOnly = FALSE)))

#R GET FILE PATH FULL#

To get the full path to the current R script in batch mode use this code.

r get file path

"-file=", "", commandArgs(trailingOnly = FALSE)Īfter saving and running this script from the command line you will get where it is located. Function dirname is returning only the directory of the file. "C:\\PROGRA~1\\R\\R-36~1.1\\bin\\圆4\\Rterm.exe"īy knowing the location of the path to the current R script that is executed in batch mode, you can extract that like this. This is the result that I will get while running the script from the command line. For example, if I’m running an R script from the Windows command line here is the result. If you are running your R script in non-interactive mode (batch mode), then you can use the function commandArgs to get the R script location. Get current R script location in batch mode If there is not, then try to look at the same thing in another RStudio-related folder. It might be helpful to know when you accidentally closed an unsaved script. So try file.path and type getwd() to see whether it has an effect on the current directory. To get the current directory, type getwd(). There should be a folder that starts with “s-” and contains what you are looking for. You can see the help by typing file.path. %USERPROFILE%\AppData\Local\RStudio-Desktop\sources

r get file path

If you have an unsaved RStudio script and RStudio is open, then try to look at this directory. Location of the unsaved RStudio script in Windows You can execute the function getSourceEditorContext() by itself to get more information about your current script. paste(ĭirname(rstudioapi::getSourceEditorContext()$path),īasename(rstudioapi::getSourceEditorContext()$path), As a result, you will get the full file path. If the saved script is already open, you can use this code in the console.

#R GET FILE PATH HOW TO#

Here is how to do that in RStudio or while running in batch mode. Are you wondering where is my current R script file located and how to determine the full path?






R get file path