R/print.R

Defines functions print.pv_query print.pv_result print.pv_query_result print.pv_relay_db print.pv_data_result print.pv_request

#' @export
print.pv_request <- function(x, ...) {
  cat(
    "#### An HTTP request where:\n\n",
    "Method: ", x$method, "\n",
    "URL: ", x$url,
    ifelse("body" %in% names(x), paste0("\nBody: ", x$body), ""),
    sep = ""
  )
}

#' @export
print.pv_data_result <- function(x, ...) {
  df <- x[[1]]

  k <- vapply(names(df), function(y) class(df[, y]), FUN.VALUE = character(1))

  dat_level <- c(
    patents = "a patent", inventors = "an inventor",
    assignees = "an assignee", locations = "a location",
    cpc_subsections = "a CPC subsection", uspc_mainclasses = "a USPC main class",
    nber_subcategories = "a NBER subcategory"
  )

  lst <- ifelse("list" %in% k, " (with list column(s) inside) ", " ")

  cat(
    "#### A list with a single data frame", lst, "on ",
    dat_level[[names(x)[1]]], " level:\n\n",
    sep = ""
  )

  utils::str(
    x, vec.len = 1, max.level = 2, give.attr = FALSE, strict.width = "cut"
  )
}

#' @export
print.pv_relay_db <- function(x, ...) {
  utils::str(
    x, vec.len = 1, max.level = 2, give.attr = FALSE, strict.width = "cut"
  )
}

#' @export
print.pv_query_result <- function(x, ...) {
  res_vec <- unlist(x)
  cat(
    "#### Distinct entity counts across all downloadable pages of output:\n\n",
    paste0(names(res_vec), " = ", format_num(res_vec), collapse = ", "),
    sep = ""
  )
}

#' @export
print.pv_result <- function(x, ...) {
  print(x[1])
  print(x[2])
}

#' @export
print.pv_query <- function(x, ...) cat(jsonlite::toJSON(x, auto_unbox = TRUE))

Try the patentsview package in your browser

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

patentsview documentation built on Sept. 25, 2021, 9:06 a.m.