R
R | Rstudio를 이용하지 않고 현재 파일이 있는 디렉토리 위치 불러오기
Chloe A_Choe
2021. 5. 6. 16:33
R script를 실행할때 매번 Rstudio를 이용할 필요는 없다. 스크립트를 한줄한줄 확인하면서 실행할 필요가없다면 바로 Rscript로 실행하면 간편하다. 그렇다면 이런경우에는 어떻게 현재 디렉토리를 지정해줄 수 있을까?
funr package의 get_script_path() function을 사용하면 된다.
funr: Simple Utility Providing Terminal Access to all R Functions
A small utility which wraps Rscript and provides access to all R functions from the shell.
cran.r-project.org
CURRENT_WORKING_DIR<- funr::get_script_path()
setwd(CURRENT_WORKING_DIR)
실행하려는 스크립트에 위와같이 설정해주면 바로 적용이 가능하다.