결과 데이터 프레임의 값을 변경하기 위해 Hadley Wickham (https://stackoverflow.com/a/12829731/2872891)의 답변에서 권장하는 stringr
기반 함수를 사용합니다. 나는 df
을 끝으로 return (df)
으로 변경하는 것을 제외하고는 그대로 함수를 그대로 두었습니다. 그러나, 나는 이상한 행동을 보았고, 그 이유가 무엇인지 모르겠습니다. replace_all
의 후속 호출, 특히 # 3 및 # 4 호출은 원래 데이터 (http:
및 mailto:
)를 복구하지 않습니다. A 재현 가능한 예이옵니다.stringr 기반 함수의 이상한 동작
데이터 (데이터의 한 기록) :
는 GitHub의에이 요점 참조하십시오
: https://gist.github.com/abnova/1709b1e0cf8a57570bd1#file-gistfile1-r코드을 (간결함을 위해, 나는 자세한 explainations 내 주석을 제거)
DATA_SEP <- ":"
rx <- "([[:alpha:]][^.:]|[[:blank:]])::([[:alpha:]][^:]|[[:blank:]])"
results <- gsub(rx, "\\[email protected]@\\2", results)
results <- gsub(": ", "[email protected]#", results) # should be after the ::-gsub
results <- gsub("http://", "http//", results)
results <- gsub("mailto:", "[email protected]", results)
results <- gsub("-\\r\\n", "-", results) # order is important here
results <- gsub("\\r\\n", " ", results)
results <- gsub("\\n:gpl:962356288", ":gpl:962356288", results)
results <- readLines(textConnection(unlist(results)))
numLines <- length(results)
results <- lapply(results, function(x) gsub(".$", "", x))
data <- read.table(textConnection(unlist(results)),
header = FALSE, fill = TRUE,
sep = DATA_SEP, quote = "",
colClasses = "character", row.names = NULL,
nrows = numLines, comment.char = "",
strip.white = TRUE)
replace_all(data, fixed("[email protected]#"), ": ")
replace_all(data, fixed("@@"), "::")
replace_all(data, fixed("http//"), "http://")
replace_all(data, fixed("[email protected]"), "mailto:")
결과 - 실제 :
> data$V3
[1] "http//www.accessgrid.org/"
> data$V17
[1] "http//[email protected]@lists.sourceforge.net"
결과 - 예상은 :
> data$V3
[1] "http://www.accessgrid.org/"
> data$V17
[1] "http://mailto:[email protected]"
나는 어떤 도움 및/또는 조언을 감사하겠습니다.
'fixed'는 패턴을 정규 문자열로 일치시킵니다. replace_all에서 패턴을 제거하고 어떤 일이 일어나는지보십시오. 근처에 컴파일러가 없습니다. – hwnd
@ hwnd : 저는 고정 된 문자열을 검색하고 대체하기 위해 의도적으로'fixed'를 사용했습니다. 그러나, 필사적으로, 나는 그것을 시도하고보고 할 것이다. 감사! –
@ hwnd : 방금 당신의 제안을 시도했습니다. 불행히도 도움이되지 않았습니다. 결과는 '고정'과 동일합니다. –