gadenbuie / metathis
1

2
#' Geotagging Metadata Tags
3
#'
4
#' @template describe-meta
5
#' @param icbm Latitude and longitude of geographic positions specified as
6
#'   `"lat, long"`. Can optionally be a length-two vector, i.e. `c(lat, long)`.
7
#' @param geo_position Latitude and longitude of geographic positions specified
8
#'   as `"lat;long"`. Can optionally be a length-two vector, i.e. `c(lat,
9
#'   long)`.
10
#' @param geo_region Name of the geographic region related to the page content,
11
#'   specified using [ISO-3166](https://en.wikipedia.org/wiki/ISO_3166)
12
#'   2-character country code and 2-character national subdivision. Example:
13
#'   `"US-NY"`.
14
#' @param geo_placename Name of the geographic place related to the page
15
#'   content. Example: `"Atlanta, Georgia"`.
16
#' @param ... Additional geotagging metadata keyword and value pairs, such as
17
#'   `geo.country`, `geo.a1`, ..., `geo.a3`, etc. Underscores in the keyword
18
#'   will be converted to periods, so you can also specify `geo_country` in
19
#'   place of `geo.country`.
20
#'
21
#' @references
22
#'   [ICBM on Wikipedia](https://en.wikipedia.org/wiki/ICBM_address#Modern_use),
23
#'   [Geotagging on Wikipedia](https://en.wikipedia.org/wiki/Geotagging#HTML_pages)
24
#'
25
#' @template describe-meta-return
26
#' @examples
27
#' meta() %>%
28
#'   meta_geo(
29
#'     icbm = c(50.167958, -97.133185),
30
#'     geo_position = c(50.167958, -97.133185),
31
#'     geo_placename = "Manitoba, Canada",
32
#'     geo_region = "ca-mb"
33
#'   )
34
#'
35
#' @export
36
meta_geo <- function(
37
  .meta = meta(),
38
  icbm = NULL,
39
  geo_position = NULL,
40
  geo_region = NULL,
41
  geo_placename = NULL,
42
  ...
43
) {
44 10
  assert_is_meta(.meta)
45

46 10
  geo_values <- list(
47 10
    ICBM            = icbm %??% collapse(icbm),
48 10
    "geo.position"  = geo_position %??% collapse(geo_position, ";"),
49 10
    "geo.region"    = geo_region,
50 10
    "geo.placename" = geo_placename,
51
    ...
52
  )
53

54 10
  meta_geo <-
55 10
    geo_values %>%
56 10
    names_replace_underscore(".") %>%
57 10
    collapse_single_string() %>%
58 10
    tag_meta_list()
59

60 10
  append_to_meta(.meta, meta_geo)
61
}

Read our documentation on viewing source code .

Loading