Skip to content

Commit

Permalink
v1.6.3 - corrected s/DCC/DDC/g and class(x)==y -> methods::is()...
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfischetti committed Aug 23, 2022
1 parent 95e4638 commit 66b48ed
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 85 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ cran-comments.md
^doc$
^Meta$
^planned-enhancements.md$
^CRAN-SUBMISSION$
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.6.3
Date: 2022-08-18 21:57:58 UTC
SHA: 95e46381ed8241d9c2b0bac1f7af9f35100e6616
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: libbib
Type: Package
Title: Various Utilities for Library Science/Assessment and Cataloging
Version: 1.6.2
Version: 1.6.3
Authors@R: person("Tony", "Fischetti",
email="[email protected]",
role=c("aut", "cre"))
Expand All @@ -14,10 +14,10 @@ Description: Provides functions for validating and normalizing bibliographic
crosswalks and code tables.
License: GPL-3
Depends: R (>= 3.5.0), data.table, utils
Imports: curl, pbapply, stringr, xml2
Imports: curl, methods, pbapply, stringr, xml2
Suggests: assertr, testthat, knitr, magrittr, rmarkdown
Encoding: UTF-8
RoxygenNote: 7.1.1
RoxygenNote: 7.2.0
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2021-05-05 13:51:08 UTC; tonyfischetti
Expand Down
31 changes: 16 additions & 15 deletions R/bibcodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ REGEX.ISSN <- "^\\d{7}(X|\\d)$"
#' @export
get_isbn_10_check_digit <- function(x, allow.hyphens=FALSE, errors.as.nas=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
if(allow.hyphens)
x <- gsub("-", "", x, fixed=TRUE)
Expand Down Expand Up @@ -98,7 +98,7 @@ get_isbn_10_check_digit <- function(x, allow.hyphens=FALSE, errors.as.nas=FALSE)
#' @export
check_isbn_10_check_digit <- function(x, allow.hyphens=TRUE, errors.as.false=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character"){
if(!methods::is(x, "character")){
if(errors.as.false)
return(rep(FALSE, length(x)))
stop("Input must be a character string")
Expand Down Expand Up @@ -146,7 +146,7 @@ check_isbn_10_check_digit <- function(x, allow.hyphens=TRUE, errors.as.false=TRU
#' @export
is_valid_isbn_10 <- function(x, allow.hyphens=TRUE, lower.x.allowed=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character"){
if(!methods::is(x, "character")){
stop("Input must be a character string")
}
if(allow.hyphens)
Expand Down Expand Up @@ -202,7 +202,7 @@ attr(is_valid_isbn_10, "assertr_vectorized") <- TRUE
#' @export
normalize_isbn_10 <- function(x, aggressive=TRUE, convert.to.isbn.13=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
x <- as.character(x)
x <- toupper(x)
x <- gsub("[^\\d|X]", "", x, perl=TRUE)
Expand Down Expand Up @@ -295,7 +295,7 @@ normalize_isbn_10 <- function(x, aggressive=TRUE, convert.to.isbn.13=FALSE){
#' @export
get_isbn_13_check_digit <- function(x, allow.hyphens=FALSE, errors.as.nas=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
if(allow.hyphens)
x <- gsub("-", "", x, fixed=TRUE)
Expand Down Expand Up @@ -342,7 +342,7 @@ get_isbn_13_check_digit <- function(x, allow.hyphens=FALSE, errors.as.nas=FALSE)
#' @export
check_isbn_13_check_digit <- function(x, allow.hyphens=TRUE, errors.as.false=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character"){
if(!methods::is(x, "character")){
if(errors.as.false)
return(rep(FALSE, length(x)))
stop("Input must be a character string")
Expand Down Expand Up @@ -384,7 +384,7 @@ check_isbn_13_check_digit <- function(x, allow.hyphens=TRUE, errors.as.false=TRU
#' @export
is_valid_isbn_13 <- function(x, allow.hyphens=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character"){
if(!methods::is(x, "character")){
stop("Input must be a character string")
}
if(allow.hyphens)
Expand Down Expand Up @@ -423,7 +423,7 @@ attr(is_valid_isbn_13, "assertr_vectorized") <- TRUE
convert_to_isbn_13 <- function(x, skip.validity.check=FALSE,
errors.as.nas=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character"){
if(!methods::is(x, "character")){
stop("Input must be a character string")
}
x <- toupper(x)
Expand Down Expand Up @@ -475,7 +475,7 @@ convert_to_isbn_13 <- function(x, skip.validity.check=FALSE,
#' @export
normalize_isbn_13 <- function(x, aggressive=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
x <- as.character(x)
x <- gsub("\\D", "", x, perl=TRUE)
is.all.valid <- all(is_valid_isbn_13(x), na.rm=TRUE)
Expand Down Expand Up @@ -542,7 +542,7 @@ normalize_isbn_13 <- function(x, aggressive=TRUE){
#' @export
normalize_isbn <- function(x, aggressive=TRUE, convert.to.isbn.13=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
x <- as.character(x)

x <- gsub("[^\\d|X|x]", "", x, perl=TRUE)
Expand Down Expand Up @@ -595,7 +595,7 @@ normalize_isbn <- function(x, aggressive=TRUE, convert.to.isbn.13=FALSE){
#' @export
get_issn_check_digit <- function(x, allow.hyphens=FALSE, errors.as.nas=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
if(allow.hyphens)
x <- gsub("-", "", x, fixed=TRUE)
Expand Down Expand Up @@ -647,7 +647,7 @@ get_issn_check_digit <- function(x, allow.hyphens=FALSE, errors.as.nas=FALSE){
#' @export
check_issn_check_digit <- function(x, allow.hyphens=TRUE, errors.as.false=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character"){
if(!methods::is(x, "character")){
if(errors.as.false)
return(rep(FALSE, length(x)))
stop("Input must be a character string")
Expand Down Expand Up @@ -697,7 +697,7 @@ check_issn_check_digit <- function(x, allow.hyphens=TRUE, errors.as.false=FALSE)
#' @export
is_valid_issn <- function(x, allow.hyphens=TRUE, lower.x.allowed=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character"){
if(!methods::is(x, "character")){
stop("Input must be a character string")
}
if(allow.hyphens)
Expand Down Expand Up @@ -759,7 +759,7 @@ attr(is_valid_issn, "assertr_vectorized") <- TRUE
#' @export
normalize_issn <- function(x, aggressive=TRUE, pretty=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
x <- as.character(x)
x <- toupper(x)
x <- gsub("[^\\d|X]", "", x, perl=TRUE)
Expand Down Expand Up @@ -857,11 +857,12 @@ normalize_issn <- function(x, aggressive=TRUE, pretty=FALSE){
#' @export
normalize_lccn <- function(userlccns, allow.hyphens=TRUE){
if(all(is.na(userlccns))) return(as.character(userlccns))
if(class(userlccns)!="character")
if(!methods::is(userlccns, "character"))
stop("Input must be a character string")

userlccns <- stringr::str_replace_all(userlccns, "\\s", "")
userlccns <- stringr::str_replace_all(userlccns, "#", "")
userlccns <- stringr::str_replace_all(userlccns, "\\^", "")
userlccns <- stringr::str_replace(userlccns, "/.+$", "")

where.bad <- !stringr::str_detect(userlccns, "\\d")
Expand Down
32 changes: 16 additions & 16 deletions R/call-numbers-and-subject.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ get_lc_call_subject_classification <- function(x, subclassification=FALSE,
already.parsed=FALSE,
allow.bare=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")

x <- stringr::str_to_upper(x)
Expand Down Expand Up @@ -141,7 +141,7 @@ get_lc_call_subject_classification <- function(x, subclassification=FALSE,
#'
#' @export
is_valid_lc_call <- function(x, allow.bare=FALSE){
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")

x <- stringr::str_to_upper(x)
Expand Down Expand Up @@ -186,7 +186,7 @@ attr(is_valid_lc_call, "assertr_vectorized") <- TRUE
#' @export
get_lc_call_first_letter <- function(x, allow.bare=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")

x <- stringr::str_to_upper(x)
Expand Down Expand Up @@ -232,7 +232,7 @@ get_lc_call_first_letter <- function(x, allow.bare=FALSE){
#' @export
get_all_lc_call_subject_letters <- function(x, allow.bare=FALSE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")

x <- stringr::str_to_upper(x)
Expand All @@ -257,16 +257,16 @@ get_all_lc_call_subject_letters <- function(x, allow.bare=FALSE){
#' Conversion from Dewey Decimal call numbers to first-level subject description
#'
#' Takes a string representation of a Dewey Decimal
#' call number (DCC) and returns it's subject description.
#' This uses the hundreds place of the DCC number
#' call number (DDC) and returns it's subject description.
#' This uses the hundreds place of the DDC number
#' and returns the most general subject classification.
#'
#' @import data.table
#'
#' @param x A Dewey Decimal call number
#'
#' @return Returns the most general subject classification using the
#' hundreds places from the DCC. Returns NA if the DCC looks
#' hundreds places from the DDC. Returns NA if the DDC looks
#' invalid
#'
#' @examples
Expand All @@ -283,7 +283,7 @@ get_all_lc_call_subject_letters <- function(x, allow.bare=FALSE){
#' @export
get_dewey_decimal_subject_class <- function(x){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")

x <- stringr::str_trim(x)
Expand All @@ -309,16 +309,16 @@ get_dewey_decimal_subject_class <- function(x){
#' Conversion from Dewey Decimal call numbers to second-level subject description
#'
#' Takes a string representation of a Dewey Decimal
#' call number (DCC) and returns it's subject description.
#' This uses the first two digits of the DCC number
#' call number (DDC) and returns it's subject description.
#' This uses the first two digits of the DDC number
#' and returns the second most general subject classification.
#'
#' @import data.table
#'
#' @param x A Dewey Decimal call number
#'
#' @return Returns the most general subject classification using the
#' first two digits from the DCC. Returns NA if the DCC looks
#' first two digits from the DDC. Returns NA if the DDC looks
#' invalid
#'
#' @examples
Expand All @@ -335,7 +335,7 @@ get_dewey_decimal_subject_class <- function(x){
#' @export
get_dewey_decimal_subject_division <- function(x){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")

x <- stringr::str_trim(x)
Expand All @@ -361,16 +361,16 @@ get_dewey_decimal_subject_division <- function(x){
#' Conversion from Dewey Decimal call numbers to third-level subject description
#'
#' Takes a string representation of a Dewey Decimal
#' call number (DCC) and returns it's subject description.
#' This uses the first three digits of the DCC number
#' call number (DDC) and returns it's subject description.
#' This uses the first three digits of the DDC number
#' and returns the third most general subject classification.
#'
#' @import data.table
#'
#' @param x A Dewey Decimal call number
#'
#' @return Returns the most general subject sectionification using the
#' first three digits from the DCC. Returns NA if the DCC looks
#' first three digits from the DDC. Returns NA if the DDC looks
#' invalid
#'
#' @examples
Expand All @@ -389,7 +389,7 @@ get_dewey_decimal_subject_division <- function(x){
#' @export
get_dewey_decimal_subject_section <- function(x){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")

x <- stringr::str_trim(x)
Expand Down
4 changes: 2 additions & 2 deletions R/marc-field-deconstruction.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#'
#' @export
marc_leader_get_info <- function(x){
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("x must be a string or NA")

record_type <- stringr::str_sub(x, 7, 7)
Expand Down Expand Up @@ -113,7 +113,7 @@ marc_leader_get_info <- function(x){
#' @export
marc_008_get_info <- function(x, original.pub.date=FALSE,
include.questionable.dates=FALSE){
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("x must be a string or NA")

pub_date <- NULL
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 @@ -25,7 +25,7 @@
#' @export
get_language_from_code <- function(x){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
x <- stringr::str_trim(stringr::str_to_lower(x))
thekey <- language <- language_code_crosswalk <- NULL
Expand Down Expand Up @@ -66,7 +66,7 @@ get_language_from_code <- function(x){
#' @export
get_country_from_code <- function(x){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
x <- stringr::str_trim(stringr::str_to_lower(x))
thekey <- country <- country_code_crosswalk <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/special-attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ set_lb_attribute <- function(x, type, value){
#'
#' @export
set_lb_date <- function(x, value){
if("Date" %chin% class(value))
if(methods::is(value, "Date"))
set_lb_attribute(x, "date", value)
else
set_lb_attribute(x, "date", as.Date(value))
Expand Down
10 changes: 5 additions & 5 deletions R/the-web.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#' @export
loc_permalink_from_lccn <- function(x, normalize=TRUE, format=""){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")

postfix <- fcase(format=="", "",
Expand Down Expand Up @@ -82,7 +82,7 @@ loc_permalink_from_lccn <- function(x, normalize=TRUE, format=""){
#' @export
worldcat_permalink_from_issn <- function(x, normalize=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
if(normalize)
x <- normalize_issn(x)
Expand Down Expand Up @@ -126,7 +126,7 @@ worldcat_permalink_from_issn <- function(x, normalize=TRUE){
#' @export
worldcat_permalink_from_isbn <- function(x, normalize=TRUE){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
if(normalize)
x <- normalize_isbn(x)
Expand Down Expand Up @@ -160,7 +160,7 @@ worldcat_permalink_from_isbn <- function(x, normalize=TRUE){
#' @export
worldcat_permalink_from_oclc_number <- function(x){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
x <- stringr::str_replace_all(x, "\\s", "")
ifelse(is.na(x), NA_character_,
Expand Down Expand Up @@ -201,7 +201,7 @@ worldcat_permalink_from_oclc_number <- function(x){
#' @export
oclc_classify_link_from_standard_num <- function(x){
if(all(is.na(x))) return(as.character(x))
if(class(x)!="character")
if(!methods::is(x, "character"))
stop("Input must be a character string")
x <- stringr::str_replace_all(x, "\\s", "")
part1 <- "http://classify.oclc.org/classify2/ClassifyDemo?search-standnum-txt="
Expand Down
Loading

0 comments on commit 66b48ed

Please sign in to comment.