Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 14 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 7 additions & 7 deletions R/call-numbers-and-subject.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
#'
Expand Down Expand Up @@ -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
#'
Expand Down Expand Up @@ -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
#'
Expand Down
1 change: 1 addition & 0 deletions R/marc-field-deconstruction.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions R/other-code-translations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions R/special-attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions R/split-map-filter-reduce.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions R/the-web.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
21 changes: 14 additions & 7 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
#' 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
#'
#' @return Returns data.table with those columns removed
#'
#' @examples
#' library(data.table)
#' mt <- as.data.table(mtcars)
#' dt_del_cols(mt, "cyl", "disp", "hp")
#'
Expand All @@ -36,14 +37,15 @@ 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
#'
#' @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")
#'
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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_]
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions R/worldcat-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions man/car.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dt_add_to_col_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dt_counts_and_percents.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dt_del_cols.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dt_keep_cols.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dt_na_breakdown.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dt_percent_not_na.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dt_set_clean_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/split_map_filter_reduce.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.