Skip to contents

The write_sf_ext and write_sf_cache helper functions wrap the sf::write_sf function to provide some additional options including consistent file naming with make_filename() and features including:

Usage

write_sf_ext(
  data,
  name = NULL,
  label = NULL,
  prefix = NULL,
  postfix = NULL,
  filename = NULL,
  filetype = NULL,
  path = NULL,
  cache = FALSE,
  overwrite = FALSE
)

write_sf_cache(
  data,
  name = NULL,
  label = NULL,
  prefix = NULL,
  postfix = NULL,
  filename = NULL,
  filetype = NULL,
  data_dir = NULL,
  overwrite = FALSE
)

write_sf_gist(
  data,
  name = NULL,
  label = NULL,
  prefix = NULL,
  postfix = NULL,
  filename = NULL,
  filetype = "geojson",
  description = NULL,
  public = TRUE,
  browse = FALSE,
  token = get_access_token(type = "GITHUB_PAT")
)

write_sf_gsheet(
  data,
  name = NULL,
  label = NULL,
  prefix = NULL,
  postfix = NULL,
  filename = NULL,
  sheet = 1,
  ask = FALSE,
  key = NULL
)

Arguments

data

sf object to write.

name

Name to make file name converted to snake case with janitor::make_clean_names(), e.g. "Residential zoning map" becomes "residential_zoning_map"

label

Label to combine with name converted to snake case with janitor::make_clean_names(). The label is designed to identify the area or other shared characteristics across multiple data files, maps, or plots.

prefix

File name prefix. "date" adds a date prefix, "time" adds a date/time prefix; defaults to NULL.

postfix

File name postfix; defaults to NULL.

filename

File name to use. If filename is provided and the data is an sf object make sure to include the file type, e.g. "data.gpkg" or "data.csv". Objects that are not simple features are written to RDS with readr::write_rds().

filetype

File type to write and cache, Default: NULL for write_sf_ext()

path

Path to file or data directory.

cache

If TRUE, write sf object to file in cache directory; defaults to FALSE.

overwrite

Logical. Default FALSE. If TRUE, overwrite any existing cached files that use the same file name.

data_dir

cache data directory, defaults to rappdirs::user_cache_dir() when data_dir is NULL. (only used for write_sf_cache; default is used when cache = TRUE for write_sf_ext)

description

(character) Brief description of gist (optional)

public

(logical) Whether gist is public (default: TRUE)

browse

(logical) To open newly create gist in default browser (default: TRUE)

token

A personal access token on GitHub with permission to create gists; defaults to Sys.getenv("GITHUB_PAT")

sheet

Sheet to write into, in the sense of "worksheet" or "tab". You can identify a sheet by name, with a string, or by position, with a number.

ask

If TRUE, the user is prompted to make revisions to the created Google Sheet. When user responds to the prompt, the date is read back into the environment using read_sf_gsheet and joined to the provided data with the column name provided to key. Defaults to FALSE.

key

If ask is TRUE, a key is required to join the sheet data to the provided data.

Details

  • If the data is not an sf object, optionally save as an RDS file.

  • If filetype is "csv" or the filename ends in ".csv" the file is automatically converted to a dataframe using df_to_sf(); if file type is "gsheet" the file is converted and turned into a new Google Sheet document (if a Google account is authorized with the googlesheets4 package using the write_sf_gsheet() function.).

  • If cache is TRUE use write_sf_cache to cache file after writing a copy to the path provided.

  • If data is a named sf list, pass the name of each sf object in the list to the name parameter and keep all other parameters consistent to write a file for each object in the list.

See also