Skip to content

Instantly share code, notes, and snippets.

@jrnold
Created January 14, 2017 00:28
Show Gist options
  • Select an option

  • Save jrnold/d91844ae649b83eb66e0ea0d6f6c5ab5 to your computer and use it in GitHub Desktop.

Select an option

Save jrnold/d91844ae649b83eb66e0ea0d6f6c5ab5 to your computer and use it in GitHub Desktop.
Load country_csv.csv
library("readr")
# see http://r4ds.had.co.nz/strings.html for functions to manipulate strings
library("stringr")
# Read individual lines into a character vector
lines <- read_lines("data/county_data.csv")
# delete the first and last character of each line
lines <- str_sub(lines, 2, -2)
# check that it worked by looking at the first line
lines[1]
# paste lines back together into a single string
# \n is the newline
lines <- str_c(lines, collapse = "\n")
# now read_tsv should work
read_tsv(lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment