Skip to contents

Use googlesheets4 to get a data frame or simple feature data from a Google Sheet

Usage

get_gsheet_data(
  url,
  sheet = NULL,
  ss = NULL,
  ask = FALSE,
  geometry = FALSE,
  location = NULL,
  dist = getOption("getdata.dist"),
  diag_ratio = getOption("getdata.diag_ratio"),
  unit = getOption("getdata.unit", "meter"),
  asp = getOption("getdata.asp"),
  coords = getOption("getdata.coords", c("lon", "lat")),
  remove_coords = TRUE,
  address = getOption("getdata.address", "address"),
  geo = FALSE,
  from_crs = 4326,
  clean_names = TRUE,
  ...
)

Arguments

url

A Google Sheets url

sheet

Sheet to read, in the sense of "worksheet" or "tab". You can identify a sheet by name, with a string, or by position, with a number. Ignored if the sheet is specified via range. If neither argument specifies the sheet, defaults to the first visible sheet.

ss

Something that identifies a Google Sheet:

  • its file id as a string or drive_id

  • a URL from which we can recover the id

  • a one-row dribble, which is how googledrive represents Drive files

  • an instance of googlesheets4_spreadsheet, which is what gs4_get() returns

Processed through as_sheets_id().

ask

If TRUE, ask for the name of the Google Sheet to read if ss is not provided to sfext::read_sf_gsheet.

geometry

Type of geometry to include in data frame. options include "drop", "wkt", "centroid", "point", Default: 'centroid'.

location

sf object. If multiple areas are provided, they are unioned into a single sf object using sf::st_union()

dist

buffer distance in units. Optional.

diag_ratio

ratio of diagonal distance of area's bounding box used as buffer distance. e.g. if the diagonal distance is 3000 meters and the "diag_ratio = 0.1" a 300 meter will be used. Ignored when dist is provided.

unit

Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; defaults to "meter"

asp

Aspect ratio of width to height as a numeric value (e.g. 0.33) or character (e.g. "1:3"). If numeric, get_asp() returns the same value without modification.

coords

Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat").

remove_coords

For df_to_sf(), if TRUE, remove the coordinate columns after converting a data frame to simple feature object; defaults to FALSE.

address

Address column name passed to tidygeocoder::geocode() or tidygeocoder::geo

geo

If TRUE, use address_to_sf() to geocode address column; defaults to FALSE.

from_crs

For df_to_sf(), coordinate reference system used by coordinates or well known text in data frame.

clean_names

If TRUE, clean names provided to nm or created based on value of col using janitor::clean_names. If FALSE, use names as provided.

...

Other parameters passed onto methods.