Quiz
You have finished the import section: reading CSV and delimited files, Excel and other formats, JSON and web data, databases and big files, and saving your results back out. This short quiz checks what stuck. Pick an answer to continue; you can retry until it clicks. The last two steps are live R, run them and tinker.
What read_csv gives you
You read a file with readr::read_csv(). What kind of object comes back?
read_csv() returns a tibble and tells you the type it guessed for each column.A number that arrived as text
A price column you expected to be numeric imports as text. What is the most likely cause?
$ or , is enough for the reader to treat the whole column as text.Reading an Excel workbook
You need to read a .xlsx workbook into R. Which package is the standard choice?
readxl::read_excel() reads both .xls and .xlsx workbooks.Two ways to save
You want to save a data frame and read it back later with its exact column types intact, including factors and dates. Which fits best?
saveRDS() round-trips the object faithfully; reach for CSV when you need a file other tools can read.Who does the work in a database query
You query a large database table with dbplyr. Where does the filtering and summarising actually happen?
Garbled accented characters
A column of names with accents imports as garbled symbols. What is the usual culprit?
A CSV round-trip in live R
Save a small data frame to a temporary CSV, then read it straight back. Run it, then add a column to shop and run again.
You wrote the frame out as text and read it back as a data frame, the core of every import: out to a file, then back into R.
saveRDS preserves the object
Save a data frame with a factor column, read it back, and confirm the types survived. Run it and read the str() output.
str(back) shows the Factor and integer types came back exactly as they went out, which CSV could not have guaranteed.
Section complete
Well done. You can read CSV with read_csv and know why a column might arrive as text, pick readxl for Excel, choose between write_csv and saveRDS for saving, reason about where a database query runs, and spot an encoding problem. Next section: strings, dates and regular expressions.