Skip to content

Instantly share code, notes, and snippets.

@dialektike
Last active July 13, 2017 06:12
Show Gist options
  • Save dialektike/fd38a8fe76f32ddf41559bac144d6878 to your computer and use it in GitHub Desktop.
Save dialektike/fd38a8fe76f32ddf41559bac144d6878 to your computer and use it in GitHub Desktop.
r에서 한글문서 열때 인코딩 문제 해결 함수. 참고: http://philogrammer.com/2017-03-15/encoding/
library(readr)
read.any <- function(text, sep = "", ...) {
encoding <- as.character(guess_encoding(text)[1,1])
setting <- as.character(tools::file_ext(text))
if(sep != "" | !(setting %in% c("csv", "txt")) ) setting <- "custom"
separate <- list(csv = ",", txt = "\n", custom = sep)
result <- read.table(text, sep = separate[[setting]], fileEncoding = encoding, ...)
return(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment