20.8 Writing to Excel

bake_sale <- tibble(
  item     = factor(c("brownie", "cupcake", "cookie")),
  quantity = c(10, 5, 8)
)


bake_sale
## # A tibble: 3 × 2
##   item    quantity
##   <fct>      <dbl>
## 1 brownie       10
## 2 cupcake        5
## 3 cookie         8
write_xlsx(bake_sale, path = "data/bake-sale.xlsx")
  • This is how the data look like in excel

Just like reading from a CSV, information on data type is lost when we read the data back in. This makes Excel files unreliable for caching interim results as well. For alternatives, see Section 8.5.

read_excel("data/bake-sale.xlsx")