2014-10-10 7 views
1

현재 URL에 삽입 할 문자열을 인코딩하려고합니다. 내 문제는 내 문자열에 백 슬래시가 포함되어 있으면 실패하는 것 같습니다. 나는 URLencode, curlEscape (RCurl에서), curlPercentEncode (RCurl에서) 함수를 사용하여 지금까지 4 가지 접근법을 시도했지만 그 중 아무 것도 성공하지 못했다.URL에 R/RCurl을 사용하여 백 슬래시 인코딩

> URLencode("hello\hello") 
Error: '\h' is an unrecognized escape in character string starting ""hello\h" 
> curlEscape("hello\hello") 
Error: '\h' is an unrecognized escape in character string starting ""hello\h" 
> curlPercentEncode("hello\hello") 
Error: '\h' is an unrecognized escape in character string starting ""hello\h" 
> curlPercentEncode("hello\hello", amp=TRUE) 
Error: '\h' is an unrecognized escape in character string starting ""hello\h" 
+3

'URLencode ("hello \\ hello")'를 사용해 보셨습니까? –

답변

2

당신은 당신이 전화를 시도의 모든 기능에서하지

> URLencode("hello\\hello") 
[1] "hello%5chello" 

당신이 얻고있는 오류입니다 찾고있다; 실제로 그것들을 부르는 것만 큼 멀리까지 가지 않았습니다. 오류는 R의 파서에서 온 것입니다. 백 슬래시는 문자열 리터럴 자체의 특수 문자이므로 더블 백 슬래시를 문자열 리터럴에 써야 백 슬래시가 포함 된 문자열 값이 생성됩니다. 예를 들어, "\""은 큰 따옴표 문자로 구성된 문자열 값을 쓰는 방법입니다. 자세한 내용은 을 읽어보십시오.

이것은 문제이므로 문자열 리터럴의 구문입니다. 데이터 소스에서 "URL에 삽입 할 문자열"을 읽는 경우에는 안됩니다. 이 문자열을 코드에 직접 작성해야하는 경우에만 문제가됩니다.