4.5 윈도우에서 나타나는 ‘Cannot Open File(파일을 열 수 없음)’ 해결하기
4.5
R
을 윈도우에서 실행 중이고
C:\data\sample.txt
와 같은 파일 이름을 사용하고 있다.
R
은 파일을 열 수 없다고 말하지만 여러분은 파일이 그 위치에 있다는 걸 확실히 알
고 있다.
파일 경로의 백슬래시가 문제를 일으키고 있는 것이다. 다음의 두 가지 방법 중 하나
로 해결할 수 있다.
·백슬래시를 슬래시로 바꾼다:
"C:/data/sample.txt"
.
·백슬래시를 쌍으로 바꾼다:
"C:\\data\\sample.txt"
.
R
에서 파일을 열 때는 파일 이름을 문자열로 전달한다. 백슬래시(
\
)가 이름에 포함
되어 있으면 문제가 되는데, 백슬래시는 문자열 안에서 특별한 의미를 가지기 때문
이다. 백슬래시를 그대로 쓰면 분명 다음과 같은 결과가 나올 것이다.
samp <- read.csv("C:\Data\sample-data.csv")
#> Error: '\D' is an unrecognized escape in character string starting ""C:\D"
R
은 백슬래시 뒤에 오는 모든 문자를 이스케이프 처리한 뒤 남은
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.