0

data <- read_delim("imported_data.csv", delim = ",")

data <- read_csv("imported_data.csv")

data <- read.csv("imported_data.csv")

data <- fread("imported_data.csv")

All these function have the same output, which one should I use? When it comes to more sophisticated functions, again what should I do? Thanks.

Freynes
  • 21
  • 5
  • The obvious question here would be: *why* are you using the first over the second? The *effect* is the same, true, but the code obviously isn’t, and the first one is more verbose and less intentional about what it does. By contrast, the second line is shorter and yet makes the intent more explicit. – Konrad Rudolph Sep 04 '21 at 14:44
  • See also: https://stackoverflow.com/questions/24424361/reason-behind-speed-of-fread-in-data-table-package-in-r – NelsonGon Sep 04 '21 at 14:52

1 Answers1

1

Use the one that's most appropriate for the situation.

If you are using Dplyr and related libraries, use read_csv or read_delim. The former is a convenience wrapper for the latter, so use whichever one seems most logical to you.

If you are using Data.table, use fread. Data.table has better performance on very large datasets, compared to Dplyr.

If you are not using either of those libraries, use read.csv or read.table because they are included in base R.

shadowtalker
  • 12,529
  • 3
  • 53
  • 96