Saving Simple Features (sf) as RDS

April 10, 2020 - 1 minutes
Miscellaneous R

This is a very short note about how to save Simple Features or sp file into a Rds file. When downloading a map data, it contains multiple file in a folder such as shp, dbf, prj, shx etc. This is quite messy after you have some manipulations.

By saving into a single rds, it is easy to read and store. I use Montreal map as example. All we need is only the sf and dplyr for manipulations and more importantly, readr from tidyverse to write and read.

library(sf)
library(dplyr)

mtl <- read_sf("maps/mtl.shp")

# some random manipulation
mtl <- mtl %>% select(NOM, TYPE)

# save as RDS, path can be specified, sometime you may compress to save some space
readr::write_rds(mtl, path = file.path("maps/mtl.rds"), compress = 'gz')

# read RDS file
montreal <- readr::read_rds('maps/mtl.rds')

# you may verify that they are the same
identical(mtl, montreal)

COVID-19 in Montreal

September 19, 2020 - 4 minutes
Statistics R Shiny

Linear Mixed Models via rstan

August 30, 2020 - 6 minutes
Statistics R

COVID-19 in Quebec

March 31, 2020 - 7 minutes
Statistics R ggplot2