R/ic_extract.R

Defines functions ic_extract_raw ic_extract

Documented in ic_extract ic_extract_raw

#' Extract raw contents of iCal fields
#'
#' Return info from iCal files, return raw unprocessed text.
#'
#' @inheritParams ic_find
#'
#' @export
#' @examples
#' pattern = "TSTAMP"
#' ic_extract_raw(ical_example, pattern)
ic_extract_raw <- function(x, pattern) {
  locations <- ic_find(x, pattern)
  x_sub <- x[locations]
  res_raw <- gsub(pattern = paste0(pattern, ":"), replacement = "", x_sub)
  res_raw
}

#' Extract contents of iCal fields
#'
#' Return formatted data from iCal fields
#'
#' @inheritParams ic_find
#'
#' @export
#' @examples
#' ic_extract(ical_example, "DTSTART")
ic_extract <- function(x, pattern) {

  res = ic_extract_raw(x, pattern) # gives the content

  if(grepl("^\\d{8}T\\d{6}Z?$", res)) {
    res = ic_datetime(res)
  }
  res
}

Try the calendar package in your browser

Any scripts or data that you put into this service are public.

calendar documentation built on May 2, 2019, 10:17 a.m.