How do you read and write data in R?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
How do you read and write data in R? Cover the common file types a data scientist meets (delimited text, R's own formats, and at least a couple of others), and say how you would choose between the options.
```hint Think about the round trip
Imagine writing a data frame to disk and reading it back. Which formats return exactly the same object, and which ones lose column types or structure along the way?
```
### What a Strong Answer Covers
- Base R and package functions for reading and writing CSV and other delimited files, and when the faster readers are worth it
- R's native formats for saving objects, and the difference between saving one object and saving several
- How to handle at least two other sources, such as Excel, JSON, Parquet or a database
- What can go wrong on read or write (column types, missing values, row names, encodings) and how to control it
### Follow-up Questions
- A CSV of customer IDs like "00123" comes back with the leading zeros gone. What happened, and how do you prevent it?
- When would you choose Parquet over RDS or CSV?
- How would you load a 20 GB file that does not fit in memory?
- What is the risk of using `load()` on an `.RData` file someone sent you?
Overview: Asks how to read and write data in R across CSV and other delimited text, R's native object files, and formats such as Excel, JSON, Parquet and databases. Tests knowledge of base and package functions, type preservation on round trips, and the default arguments that cause bugs.