파일 > 작업 디렉토리 바꾸기...
File > Change working directory...

Windows 사례 (7)


R이 시작되는 곳, 불러올 데이터가 보관되는 곳, 그리고 데이터를 저장할 곳이 다른 경우가 흔히 발생한다. 흔히 '경로' 변경과 관련된 일인데, 일일이 수작업으로 입력하기가 불편하다. GUI 환경에서 R 작업을 할 때, 효과적인 영역이다.

- MS-Windows 경우, user > 문서 경로부터 화면이 시작된다.

- Linux 경우, home/사용자 경로부터 화면이 시작된다.

Linux 사례 (MX 21)



관련된 함수는 getwd(), setwd() 등이 있다.

?setwd  # 작업 디렉토리 (변경)설정 도움말 보기

getwd {base} R Documentation

Get or Set Working Directory

Description

getwd returns an absolute filepath representing the current working directory of the R process; setwd(dir) is used to set the working directory to dir.

Usage

getwd()
setwd(dir)

Arguments

dir A character string: tilde expansion will be done.

Details

See files for how file paths with marked encodings are interpreted.

Value

getwd returns a character string or NULL if the working directory is not available. On Windows the path returned will use / as the path separator and be encoded in UTF-8. The path will not have a trailing / unless it is the root directory (of a drive or share on Windows).

setwd returns the current directory before the change, invisibly and with the same conventions as getwd. It will give an error if it does not succeed (including if it is not implemented).

Note

Note that the return value is said to be an absolute filepath: there can be more than one representation of the path to a directory and on some OSes the value returned can differ after changing directories and changing back to the same directory (for example if symbolic links have been traversed).

See Also

list.files for the contents of a directory.

normalizePath for a ‘canonical’ path name.

Examples

(WD <- getwd())
if (!is.null(WD)) setwd(WD)

[Package base version 4.0.4 Index]

+ Recent posts