-1

I want to save each dataframe from list with its according names as .fst file. My list with dataframes is called tables. I tried to do this, but it didn't work:

lapply(write_fst(), tables)

How to do that? How to perform write_fst function to each dataframe in list?

  • `lapply(tables, write_fst)` ? – Ronak Shah Jul 08 '21 at 12:05
  • @RonakShah but how to specify dataframes names to make them same as in list with .fst extension? also isn't it applying a function to list, not values in it separately? –  Jul 08 '21 at 12:06
  • Which package is `write_fst` function from? Do you have some example data? – Ronak Shah Jul 08 '21 at 12:18
  • @RonakShah its from library fst http://www.fstpackage.org/reference/write_fst.html –  Jul 08 '21 at 12:20

2 Answers2

1

You can try using Map -

Map(write_fst, tables, names(tables))

If the names of the list do not have extension (.fst) you can use paste0 to add it.

Map(write_fst, tables, paste0(names(tables), '.fst'))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
1

You can loop through a list of data.frames:

require(fst)

l = list(
  iris = iris,
  mtcars = mtcars,
  airquality = airquality
)

for (i in seq_along(l)) {
  write_fst(l[[i]], path = paste0(names(l)[i], '.fst'))
}
andschar
  • 3,504
  • 2
  • 27
  • 35