Created
October 13, 2014 14:23
-
-
Save christophergandrud/33408807b2d0ab7b6bd0 to your computer and use it in GitHub Desktop.
Convert text files in a directory to UTF-8 encoding (http://en.wikipedia.org/wiki/UTF-8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Convert text files in a directory to UTF-8 encoding | |
#' | |
#' @param dir a character string naming the directory where the files are located. | |
#' @param new_dir a character string naming the directory where you would like the | |
#' converted files to be placed. | |
#' | |
#' @importFrom dplyr %>% | |
utf8_convert <- function(dir, new_dir){ | |
all_files <- list.files(dir) | |
for (i in all_files){ | |
old_path <- paste0('TextFiles_AllTogether/', i) | |
temp <- paste(readLines(old_path), collapse = ' ') %>% | |
iconv(to = 'UTF-8', sub = '') | |
cat(temp, file = paste0(new_dir, i)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment