diff --git a/DESCRIPTION b/DESCRIPTION index 9e0c691..ecf406a 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,13 +13,13 @@ Description: Provides functions for validating and normalizing bibliographic and provides various loadable data files such call number / subject crosswalks and code tables. License: GPL-3 -Depends: R (>= 3.5.0), data.table, utils -Imports: curl, methods, pbapply, stringr, xml2 +Depends: R (>= 3.5.0), utils +Imports: curl, data.table, methods, pbapply, stringr, xml2 Suggests: assertr, testthat, knitr, magrittr, rmarkdown Encoding: UTF-8 -RoxygenNote: 7.2.1 VignetteBuilder: knitr NeedsCompilation: no Packaged: 2021-05-05 13:51:08 UTC; tonyfischetti Author: Tony Fischetti [aut, cre] URL: https://github.com/NYPL/libbib +Config/roxygen2/version: 8.0.0 diff --git a/NAMESPACE b/NAMESPACE index b64330f..97a156a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -58,6 +58,19 @@ export(worldcat_api_search) export(worldcat_permalink_from_isbn) export(worldcat_permalink_from_issn) export(worldcat_permalink_from_oclc_number) -import(data.table) import(pbapply) import(utils) +importFrom(data.table,"%chin%") +importFrom(data.table,":=") +importFrom(data.table,.N) +importFrom(data.table,as.data.table) +importFrom(data.table,copy) +importFrom(data.table,data.table) +importFrom(data.table,fcase) +importFrom(data.table,fread) +importFrom(data.table,fwrite) +importFrom(data.table,rbindlist) +importFrom(data.table,setattr) +importFrom(data.table,setcolorder) +importFrom(data.table,setindex) +importFrom(data.table,setnames) diff --git a/R/call-numbers-and-subject.R b/R/call-numbers-and-subject.R index 07458d7..fb63755 100755 --- a/R/call-numbers-and-subject.R +++ b/R/call-numbers-and-subject.R @@ -28,7 +28,7 @@ REGEX.VALID.LCCALL.BARE <- make.valid.lccall.regex(allow.bare=TRUE) #' letter, or a second-level subclassification #' description based on the all the letters #' -#' @import data.table +#' @importFrom data.table := data.table setindex #' #' @param x A Library of Congress call number (string) #' @param subclassification A logical indicating whether the letters of @@ -119,7 +119,7 @@ get_lc_call_subject_classification <- function(x, subclassification=FALSE, #' whether or not the input fits the canonical LC Call #' Number pattern #' -#' @import data.table +#' @importFrom data.table := data.table setindex #' #' @param x A Library of Congress call number (string) #' @param allow.bare A logical indicating whether an LC Call with only @@ -164,7 +164,7 @@ attr(is_valid_lc_call, "assertr_vectorized") <- TRUE #' call number and returns the first letter if and only if #' the LC Call Number is valid #' -#' @import data.table +#' @importFrom data.table := data.table setindex #' #' @param x A Library of Congress call number (string) #' @param allow.bare A logical indicating whether an LC Call with only @@ -209,7 +209,7 @@ get_lc_call_first_letter <- function(x, allow.bare=FALSE){ #' call number and returns all the subject letters if and only if #' the LC Call Number is valid #' -#' @import data.table +#' @importFrom data.table := data.table setindex #' @import utils #' #' @param x A Library of Congress call number (string) @@ -261,7 +261,7 @@ get_all_lc_call_subject_letters <- function(x, allow.bare=FALSE){ #' This uses the hundreds place of the DDC number #' and returns the most general subject classification. #' -#' @import data.table +#' @importFrom data.table := data.table setindex #' #' @param x A Dewey Decimal call number #' @@ -313,7 +313,7 @@ get_dewey_decimal_subject_class <- function(x){ #' This uses the first two digits of the DDC number #' and returns the second most general subject classification. #' -#' @import data.table +#' @importFrom data.table := data.table setindex #' #' @param x A Dewey Decimal call number #' @@ -365,7 +365,7 @@ get_dewey_decimal_subject_division <- function(x){ #' This uses the first three digits of the DDC number #' and returns the third most general subject classification. #' -#' @import data.table +#' @importFrom data.table := data.table setindex #' #' @param x A Dewey Decimal call number #' diff --git a/R/marc-field-deconstruction.R b/R/marc-field-deconstruction.R index c7952da..7eacf2f 100755 --- a/R/marc-field-deconstruction.R +++ b/R/marc-field-deconstruction.R @@ -25,6 +25,7 @@ #' # 3: Cartographic material Monograph/Item #' #' @export +#' @importFrom data.table fcase marc_leader_get_info <- function(x){ if(!methods::is(x, "character")) stop("x must be a string or NA") diff --git a/R/other-code-translations.R b/R/other-code-translations.R index 5d1bf28..0e1db44 100755 --- a/R/other-code-translations.R +++ b/R/other-code-translations.R @@ -5,7 +5,7 @@ #' Takes a language code (defined in the Marc standards) #' and returns the language name. #' -#' @import data.table +#' @importFrom data.table data.table setindex #' #' @param x A language code (defined in the Marc standards) or a vector #' of language codes @@ -46,7 +46,7 @@ get_language_from_code <- function(x){ #' Interestingly, although it's called 'country' in the Marc standard, #' cities, states, and other non-countries also have codes #' -#' @import data.table +#' @importFrom data.table data.table setindex #' #' @param x A country code (defined in the Marc standards) or a vector #' of country codes diff --git a/R/special-attributes.R b/R/special-attributes.R index 8f0e666..682da92 100755 --- a/R/special-attributes.R +++ b/R/special-attributes.R @@ -5,7 +5,7 @@ #' Takes an object, attribute name, and a value and sets a special #' libbib attribute by reference #' -#' @import data.table +#' @importFrom data.table fread fwrite setattr #' #' @param x An object to set the attribute on #' @param type The name of the attribute to set. \code{lb.} will be appended @@ -35,7 +35,7 @@ set_lb_attribute <- function(x, type, value){ #' Takes an object and a date and sets a special attribute, "lb.date" #' by reference #' -#' @import data.table +#' @importFrom data.table fread fwrite setattr #' #' @param x An object to set the attribute on #' @param value Either a value of class \code{Date} or a string in ISO 8601 @@ -66,7 +66,7 @@ set_lb_date <- function(x, value){ #' (attributes beginning with \code{lb.}) from the first object #' to the second, by reference. #' -#' @import data.table +#' @importFrom data.table fread fwrite setattr #' #' @param a The first object (the one with the attributes to copy) #' @param b The second object (the one to copy those attributes to) @@ -162,7 +162,7 @@ fread_plus_helper <- function(fname){ #' \code{allow.fallback.date} is \code{TRUE}, then the \code{lb.date} #' attribute is set to the current date. #' -#' @import data.table +#' @importFrom data.table fread fwrite setattr #' #' @param fname The file name to read #' @param allow.fallback.date A logical indicating whether, if no @@ -243,7 +243,7 @@ fread_plus_date <- function(fname, allow.fallback.date=TRUE, ...){ #' the base file name (after any directories) with the exception of #' the file extension. #' -#' @import data.table +#' @importFrom data.table fread fwrite setattr #' #' @param DT a \code{data.table} to write to disk #' @param fname The file name to write the \code{data.table} to. The diff --git a/R/split-map-filter-reduce.R b/R/split-map-filter-reduce.R index 4ed9474..772fa1c 100755 --- a/R/split-map-filter-reduce.R +++ b/R/split-map-filter-reduce.R @@ -16,6 +16,7 @@ #' @seealso \code{\link{split_map_filter_reduce}} #' #' @examples +#' library(data.table) #' car(c(8, 6, 7, 5, 3, 0, 9)) # 8 #' mt <- as.data.table(mtcars) #' dt_del_cols(mt, "cyl", "disp", "hp") diff --git a/R/the-web.R b/R/the-web.R index fc8a967..3af825b 100755 --- a/R/the-web.R +++ b/R/the-web.R @@ -33,6 +33,7 @@ #' # "https://lccn.loc.gov/73167510/marcxml" #' #' @export +#' @importFrom data.table fcase loc_permalink_from_lccn <- function(x, normalize=TRUE, format=""){ if(all(is.na(x))) return(as.character(x)) if(!methods::is(x, "character")) diff --git a/R/utilities.R b/R/utilities.R index 2a08bbe..d761264 100755 --- a/R/utilities.R +++ b/R/utilities.R @@ -9,7 +9,7 @@ #' Takes a data.table and a quoted sequence of column names #' and removes the specified column names from the data.table #' -#' @import data.table +#' @importFrom data.table := %chin% .N as.data.table copy data.table setnames #' #' @param DT A data.table #' @param ... arbitrary number of column names in quotes @@ -17,6 +17,7 @@ #' @return Returns data.table with those columns removed #' #' @examples +#' library(data.table) #' mt <- as.data.table(mtcars) #' dt_del_cols(mt, "cyl", "disp", "hp") #' @@ -36,7 +37,7 @@ dt_del_cols <- function(DT, ...){ #' Takes a data.table and a quoted sequence of column names #' and removes all columns but the ones specified #' -#' @import data.table +#' @importFrom data.table := %chin% .N as.data.table copy data.table setnames #' #' @param DT A data.table #' @param ... arbitrary number of column names in quotes @@ -44,6 +45,7 @@ dt_del_cols <- function(DT, ...){ #' @return Returns data.table with only those columns #' #' @examples +#' library(data.table) #' mt <- as.data.table(mtcars) #' dt_keep_cols(mt, "mpg", "am", "gear", "carb") #' @@ -119,7 +121,7 @@ dt_pivot <- function(DT, theby, theexp, percent.cutoff=0, value.name="value", #' The quoted group-by variable must be a character or factor. If it is #' not, it will be temporarily converted into one and a warning is issued. #' -#' @import data.table +#' @importFrom data.table := %chin% .N as.data.table copy data.table setnames #' #' @param DT The data.table object to operate on #' @param group_by_this A quoted column to group by @@ -137,6 +139,7 @@ dt_pivot <- function(DT, theby, theexp, percent.cutoff=0, value.name="value", #' percent column (out of 100) to two decimal places #' #' @examples +#' library(data.table) #' #' iris_dt <- as.data.table(iris) #' dt_counts_and_percents(iris_dt, "Species") @@ -231,7 +234,7 @@ get_clean_names <- function(dat, lower=TRUE){ #' All space/whitespace characters are replaced with underscores, #' as are all characters not from A-Z, a-z, an underscore, or a digit #' -#' @import data.table +#' @importFrom data.table := %chin% .N as.data.table copy data.table setnames #' #' @param DT a data.table #' @param lower A logical indicating whether all column names should be @@ -242,6 +245,7 @@ get_clean_names <- function(dat, lower=TRUE){ #' @seealso \code{\link{get_clean_names}} #' #' @examples +#' library(data.table) #' #' ejemplo <- as.data.table(iris) #' setnames(ejemplo, c("Sepal Length", "Sepal@Width", "Petal Length", @@ -265,7 +269,7 @@ dt_set_clean_names <- function(DT, lower=TRUE){ #' NA. #' The percent is out of 100 and contains up to two decimal places #' -#' @import data.table +#' @importFrom data.table := %chin% .N as.data.table copy data.table setnames #' #' @param DT A data.table object #' @param acolumn a quoted column name @@ -275,6 +279,7 @@ dt_set_clean_names <- function(DT, lower=TRUE){ #' @seealso \code{\link{is.na}} #' #' @examples +#' library(data.table) #' #' mt <- as.data.table(mtcars) #' mt[mpg<16, mpg:=NA] @@ -303,7 +308,7 @@ dt_percent_not_na <- function(DT, acolumn){ #' #' The quoted group-by variable must be a character or factor #' -#' @import data.table +#' @importFrom data.table := %chin% .N as.data.table copy data.table setnames #' #' @param DT The data.table object to operate on #' @param acolumn a quoted column name @@ -317,6 +322,7 @@ dt_percent_not_na <- function(DT, acolumn){ #' percent column (out of 100) to two decimal places #' #' @examples +#' library(data.table) #' #' iris_dt <- as.data.table(iris) #' iris_dt[sample(1:.N, 10), Species:=NA_character_] @@ -347,7 +353,7 @@ dt_na_breakdown <- function(DT, acolumn, big.mark=FALSE){ #' be added to end of the each column's name. If \code{prefix} #' is \code{TRUE}, the string is added to the beginning, instead. #' -#' @import data.table +#' @importFrom data.table := %chin% .N as.data.table copy data.table setnames #' #' @param DT A data.table #' @param astring A string to add to each column name @@ -372,6 +378,7 @@ dt_na_breakdown <- function(DT, acolumn, big.mark=FALSE){ #' column names. #' #' @examples +#' library(data.table) #' DT <- as.data.table(iris) #' #' dt_add_to_col_names(DT, "_post") diff --git a/R/worldcat-api.R b/R/worldcat-api.R index bb8de24..06cd591 100755 --- a/R/worldcat-api.R +++ b/R/worldcat-api.R @@ -1069,6 +1069,7 @@ worldcat_api_search_helper <- function(sru, max_records=100, #' #' } #' @export +#' @importFrom data.table fcase rbindlist setcolorder worldcat_api_search <- function(sru, max_records=10, sru_query_assist=getOption("libbib.sru_query_assist", TRUE), frbrGrouping="on", start_at=1, diff --git a/man/car.Rd b/man/car.Rd index 7339703..4db84e7 100644 --- a/man/car.Rd +++ b/man/car.Rd @@ -20,6 +20,7 @@ Equivalent to Lisp's \code{car} function Originally for use as a reduction function in \code{split_map_filter_reduce} } \examples{ +library(data.table) car(c(8, 6, 7, 5, 3, 0, 9)) # 8 mt <- as.data.table(mtcars) dt_del_cols(mt, "cyl", "disp", "hp") diff --git a/man/dt_add_to_col_names.Rd b/man/dt_add_to_col_names.Rd index 15abd4e..85e6903 100644 --- a/man/dt_add_to_col_names.Rd +++ b/man/dt_add_to_col_names.Rd @@ -48,6 +48,7 @@ be added to end of the each column's name. If \code{prefix} is \code{TRUE}, the string is added to the beginning, instead. } \examples{ +library(data.table) DT <- as.data.table(iris) dt_add_to_col_names(DT, "_post") diff --git a/man/dt_counts_and_percents.Rd b/man/dt_counts_and_percents.Rd index ad48523..1e9bcbb 100644 --- a/man/dt_counts_and_percents.Rd +++ b/man/dt_counts_and_percents.Rd @@ -43,6 +43,7 @@ The quoted group-by variable must be a character or factor. If it is not, it will be temporarily converted into one and a warning is issued. } \examples{ +library(data.table) iris_dt <- as.data.table(iris) dt_counts_and_percents(iris_dt, "Species") diff --git a/man/dt_del_cols.Rd b/man/dt_del_cols.Rd index 8b6b04b..96ccc19 100644 --- a/man/dt_del_cols.Rd +++ b/man/dt_del_cols.Rd @@ -19,6 +19,7 @@ Takes a data.table and a quoted sequence of column names and removes the specified column names from the data.table } \examples{ +library(data.table) mt <- as.data.table(mtcars) dt_del_cols(mt, "cyl", "disp", "hp") diff --git a/man/dt_keep_cols.Rd b/man/dt_keep_cols.Rd index 870e310..642dd4f 100644 --- a/man/dt_keep_cols.Rd +++ b/man/dt_keep_cols.Rd @@ -19,6 +19,7 @@ Takes a data.table and a quoted sequence of column names and removes all columns but the ones specified } \examples{ +library(data.table) mt <- as.data.table(mtcars) dt_keep_cols(mt, "mpg", "am", "gear", "carb") diff --git a/man/dt_na_breakdown.Rd b/man/dt_na_breakdown.Rd index c276592..928d3fb 100644 --- a/man/dt_na_breakdown.Rd +++ b/man/dt_na_breakdown.Rd @@ -34,6 +34,7 @@ The final row is a total count The quoted group-by variable must be a character or factor } \examples{ +library(data.table) iris_dt <- as.data.table(iris) iris_dt[sample(1:.N, 10), Species:=NA_character_] diff --git a/man/dt_percent_not_na.Rd b/man/dt_percent_not_na.Rd index 1614e6e..02727b7 100644 --- a/man/dt_percent_not_na.Rd +++ b/man/dt_percent_not_na.Rd @@ -21,6 +21,7 @@ NA. The percent is out of 100 and contains up to two decimal places } \examples{ +library(data.table) mt <- as.data.table(mtcars) mt[mpg<16, mpg:=NA] diff --git a/man/dt_set_clean_names.Rd b/man/dt_set_clean_names.Rd index 90bf9e5..25883a9 100644 --- a/man/dt_set_clean_names.Rd +++ b/man/dt_set_clean_names.Rd @@ -25,6 +25,7 @@ All space/whitespace characters are replaced with underscores, as are all characters not from A-Z, a-z, an underscore, or a digit } \examples{ +library(data.table) ejemplo <- as.data.table(iris) setnames(ejemplo, c("Sepal Length", "Sepal@Width", "Petal Length", diff --git a/man/split_map_filter_reduce.Rd b/man/split_map_filter_reduce.Rd index 070492a..9c4c583 100644 --- a/man/split_map_filter_reduce.Rd +++ b/man/split_map_filter_reduce.Rd @@ -53,7 +53,7 @@ Returns a vector } \description{ This function takes a vector of strings, splits those strings -on a particular character; string; or regex patters, applies a +on a particular character; string; or regex pattern, applies a user-specified function to each sub-element of the now split element, filters those sub-elements using a user-specified function, and, finally, recombines each element's sub-elements using a user specified reduction