From 2409e32a7bf02d0adf017bd0934ed032c28a16d0 Mon Sep 17 00:00:00 2001 From: "Mathew W. McLean" Date: Sat, 1 Oct 2022 00:05:31 +1000 Subject: [PATCH] Shorten doc. examples for CRAN --- R/BibEntryExtractOp.R | 90 ++++++++++++++++++++--------------------- R/BibEntryReplaceOp.R | 16 +++++++- R/ReadBib.R | 13 +++++- man/ReadBib.Rd | 13 +++++- man/SearchBib.Rd | 90 ++++++++++++++++++++--------------------- man/subset-.BibEntry.Rd | 16 +++++++- 6 files changed, 140 insertions(+), 98 deletions(-) diff --git a/R/BibEntryExtractOp.R b/R/BibEntryExtractOp.R index 813e723..80d891a 100755 --- a/R/BibEntryExtractOp.R +++ b/R/BibEntryExtractOp.R @@ -96,68 +96,64 @@ MatchName <- function(nom, pattern, match.author=.BibOptions$match.author, #' @family operators #' @rdname SearchBib #' @examples -#' if (requireNamespace("bibtex")) { -#' file.name <- system.file("Bib", "biblatexExamples.bib", package="RefManageR") -#' bib <- suppressMessages(ReadBib(file.name)) +#' file.name <- system.file("Bib", "biblatexExamples.bib", package="RefManageR") +#' bib <- suppressMessages(ReadBib(file.name)) #' -#' ## author search, default is to use family names only for matching -#' bib[author = "aristotle"] +#' ## author search, default is to use family names only for matching +#' bib[author = "aristotle"] #' -#' ## Aristotle references before 1925 -#' bib[author="aristotle", date = "/1925"] +#' ## Aristotle references before 1925 +#' bib[author="aristotle", date = "/1925"] #' -#' ## Aristotle references before 1925 *OR* references with editor Westfahl -#' bib[list(author="aristotle", date = "/1925"),list(editor = "westfahl")] +#' ## Aristotle references before 1925 *OR* references with editor Westfahl +#' bib[list(author="aristotle", date = "/1925"),list(editor = "westfahl")] #' -#' ## Change some searching and printing options and search for author -#' old.opts <- BibOptions(bib.style = "authoryear", match.author = "exact", -#' max.names = 99, first.inits = FALSE) -#' bib[author="Mart\u00edn, Jacinto and S\u00e1nchez, Alberto"] -#' BibOptions(old.opts) ## reset options +#' ## Change some searching and printing options and search for author +#' old.opts <- BibOptions(bib.style = "authoryear", match.author = "exact", +#' max.names = 99, first.inits = FALSE) +#' bib[author="Mart\u00edn, Jacinto and S\u00e1nchez, Alberto"] +#' BibOptions(old.opts) ## reset options #' -#' ## Some works of Raymond J. Carroll's -#' file.name <- system.file("Bib", "RJC.bib", package="RefManageR") -#' bib <- ReadBib(file.name) -#' length(bib) +#' \dontrun{ +#' ## Some works of Raymond J. Carroll's +#' file.name <- system.file("Bib", "RJC.bib", package="RefManageR") +#' bib <- ReadBib(file.name) +#' length(bib) #' -#' ## index by key -#' bib[c("chen2013using", "carroll1978distributions")] +#' ## index by key +#' bib[c("chen2013using", "carroll1978distributions")] #' -#' ## Papers with someone with family name Wang -#' length(SearchBib(bib, author='Wang', .opts = list(match.author = "family"))) +#' ## Papers with someone with family name Wang +#' length(SearchBib(bib, author='Wang', .opts = list(match.author = "family"))) #' -#' ## Papers with Wang, N. -#' length(SearchBib(bib, author='Wang, N.', .opts = list(match.author = "family.with.initials"))) +#' ## Papers with Wang, N. +#' length(SearchBib(bib, author='Wang, N.', .opts = list(match.author = "family.with.initials"))) #' -#' ## tech reports with Ruppert -#' length(bib[author='ruppert',bibtype="report"]) +#' ## tech reports with Ruppert +#' length(bib[author='ruppert',bibtype="report"]) #' -#' ##Carroll and Ruppert tech reports at UNC -#' length(bib[author='ruppert',bibtype="report",institution="north carolina"]) +#' ##Carroll and Ruppert tech reports at UNC +#' length(bib[author='ruppert',bibtype="report",institution="north carolina"]) #' -#' ## Carroll and Ruppert papers since leaving UNC -#' length(SearchBib(bib, author='ruppert', date="1987-07/", -#' .opts = list(match.date = "exact"))) -#' } +#' ## Carroll and Ruppert papers since leaving UNC +#' length(SearchBib(bib, author='ruppert', date="1987-07/", +#' .opts = list(match.date = "exact"))) #' -#' ## Carroll and Ruppert papers NOT in the 1990's -#' \dontrun{ -#' if (requireNamespace("bibtex")) { -#' length(SearchBib(bib, author='ruppert', date = "!1990/1999")) -#' identical(SearchBib(bib, author='ruppert', date = "!1990/1999"), -#' SearchBib(bib, author='ruppert', year = "!1990/1999")) -#' table(unlist(SearchBib(bib, author='ruppert', date="!1990/1999")$year)) +#' ## Carroll and Ruppert papers NOT in the 1990's +#' length(SearchBib(bib, author='ruppert', date = "!1990/1999")) +#' identical(SearchBib(bib, author='ruppert', date = "!1990/1999"), +#' SearchBib(bib, author='ruppert', year = "!1990/1999")) +#' table(unlist(SearchBib(bib, author='ruppert', date="!1990/1999")$year)) #' -#' ## Carroll + Ruppert + Simpson -#' length(bib[author="Carroll, R. J. and Simpson, D. G. and Ruppert, D."]) +#' ## Carroll + Ruppert + Simpson +#' length(bib[author="Carroll, R. J. and Simpson, D. G. and Ruppert, D."]) #' -#' ## Carroll + Ruppert OR Carroll + Simpson -#' length(bib[author=c("Carroll, R. J. and Ruppert, D.", "Carroll, R. J. and Simpson, D. G.")]) +#' ## Carroll + Ruppert OR Carroll + Simpson +#' length(bib[author=c("Carroll, R. J. and Ruppert, D.", "Carroll, R. J. and Simpson, D. G.")]) #' -#' ## Carroll + Ruppert tech reports at UNC "OR" Carroll and Ruppert JASA papers -#' length(bib[list(author='ruppert',bibtype="report",institution="north carolina"), -#' list(author="ruppert",journal="journal of the american statistical association")]) -#' } +#' ## Carroll + Ruppert tech reports at UNC "OR" Carroll and Ruppert JASA papers +#' length(bib[list(author='ruppert',bibtype="report",institution="north carolina"), +#' list(author="ruppert",journal="journal of the american statistical association")]) #' } `[.BibEntry` <- function(x, i, j, ..., drop = FALSE){ diff --git a/R/BibEntryReplaceOp.R b/R/BibEntryReplaceOp.R index 105da91..46f6301 100644 --- a/R/BibEntryReplaceOp.R +++ b/R/BibEntryReplaceOp.R @@ -20,7 +20,21 @@ #' @keywords methods manip #' @family operators #' @examples -#' if (requireNamespace("bibtex")) { +#' bib.text <- "@Manual{mclean2014, +#' author = {Mathew William McLean}, +#' title = {Straightforward Bibliography Management in R Using the RefManager Package}, +#' note = {arXiv: 1403.2036 [cs.DL]}, +#' year = {2014}, +#' url = {https://arxiv.org/abs/1403.2036}, +#' }" +#' tfile <- tempfile(fileext = ".bib") +#' writeLines(bib.text, tfile) +#' bib <- ReadBib(tfile) +#' bib[1] <- list(c(date = "2014-03", key = "mwm2014")) +#' bib +#' unlink(tfile) +#' +#' \dontrun{ #' file.name <- system.file("Bib", "RJC.bib", package="RefManageR") #' bib <- ReadBib(file.name) #' print(bib[seq_len(3L)], .opts = list(sorting = "none", bib.style = "alphabetic")) diff --git a/R/ReadBib.R b/R/ReadBib.R index 7df21ac..11f3e9e 100755 --- a/R/ReadBib.R +++ b/R/ReadBib.R @@ -24,7 +24,18 @@ #' @seealso \code{\link[bibtex]{read.bib}} in package \code{bibtex} #' @export #' @examples -#' if (requireNamespace("bibtex")) { +#' bib.text <- "@Manual{mclean2014, +#' author = {Mathew William McLean}, +#' title = {Straightforward Bibliography Management in R Using the RefManager Package}, +#' note = {arXiv: 1403.2036 [cs.DL]}, +#' year = {2014}, +#' url = {https://arxiv.org/abs/1403.2036}, +#' }" +#' tfile <- tempfile(fileext = ".bib") +#' writeLines(bib.text, tfile) +#' ReadBib(tfile) +#' unlink(tfile) +#' \dontrun{ #' file.name <- system.file("Bib", "RJC.bib", package="RefManageR") #' bib <- ReadBib(file.name) #' } diff --git a/man/ReadBib.Rd b/man/ReadBib.Rd index d8d4450..f4626b1 100755 --- a/man/ReadBib.Rd +++ b/man/ReadBib.Rd @@ -41,7 +41,18 @@ Keys will be made unique by calling \code{\link[base]{make.unique}} with \code{sep = ":"}. } \examples{ -if (requireNamespace("bibtex")) { +bib.text <- "@Manual{mclean2014, + author = {Mathew William McLean}, + title = {Straightforward Bibliography Management in R Using the RefManager Package}, + note = {arXiv: 1403.2036 [cs.DL]}, + year = {2014}, + url = {https://arxiv.org/abs/1403.2036}, +}" +tfile <- tempfile(fileext = ".bib") +writeLines(bib.text, tfile) +ReadBib(tfile) +unlink(tfile) +\dontrun{ file.name <- system.file("Bib", "RJC.bib", package="RefManageR") bib <- ReadBib(file.name) } diff --git a/man/SearchBib.Rd b/man/SearchBib.Rd index 4bb1d72..78631e0 100755 --- a/man/SearchBib.Rd +++ b/man/SearchBib.Rd @@ -59,68 +59,64 @@ operator by changing the corresponding option in the .BibOptions object; see \code{\link{BibOptions}}. } \examples{ -if (requireNamespace("bibtex")) { - file.name <- system.file("Bib", "biblatexExamples.bib", package="RefManageR") - bib <- suppressMessages(ReadBib(file.name)) +file.name <- system.file("Bib", "biblatexExamples.bib", package="RefManageR") +bib <- suppressMessages(ReadBib(file.name)) - ## author search, default is to use family names only for matching - bib[author = "aristotle"] +## author search, default is to use family names only for matching +bib[author = "aristotle"] - ## Aristotle references before 1925 - bib[author="aristotle", date = "/1925"] +## Aristotle references before 1925 +bib[author="aristotle", date = "/1925"] - ## Aristotle references before 1925 *OR* references with editor Westfahl - bib[list(author="aristotle", date = "/1925"),list(editor = "westfahl")] +## Aristotle references before 1925 *OR* references with editor Westfahl +bib[list(author="aristotle", date = "/1925"),list(editor = "westfahl")] - ## Change some searching and printing options and search for author - old.opts <- BibOptions(bib.style = "authoryear", match.author = "exact", - max.names = 99, first.inits = FALSE) - bib[author="Mart\u00edn, Jacinto and S\u00e1nchez, Alberto"] - BibOptions(old.opts) ## reset options +## Change some searching and printing options and search for author +old.opts <- BibOptions(bib.style = "authoryear", match.author = "exact", + max.names = 99, first.inits = FALSE) +bib[author="Mart\u00edn, Jacinto and S\u00e1nchez, Alberto"] +BibOptions(old.opts) ## reset options - ## Some works of Raymond J. Carroll's - file.name <- system.file("Bib", "RJC.bib", package="RefManageR") - bib <- ReadBib(file.name) - length(bib) +\dontrun{ + ## Some works of Raymond J. Carroll's + file.name <- system.file("Bib", "RJC.bib", package="RefManageR") + bib <- ReadBib(file.name) + length(bib) - ## index by key - bib[c("chen2013using", "carroll1978distributions")] + ## index by key + bib[c("chen2013using", "carroll1978distributions")] - ## Papers with someone with family name Wang - length(SearchBib(bib, author='Wang', .opts = list(match.author = "family"))) + ## Papers with someone with family name Wang + length(SearchBib(bib, author='Wang', .opts = list(match.author = "family"))) - ## Papers with Wang, N. - length(SearchBib(bib, author='Wang, N.', .opts = list(match.author = "family.with.initials"))) + ## Papers with Wang, N. + length(SearchBib(bib, author='Wang, N.', .opts = list(match.author = "family.with.initials"))) - ## tech reports with Ruppert - length(bib[author='ruppert',bibtype="report"]) + ## tech reports with Ruppert + length(bib[author='ruppert',bibtype="report"]) - ##Carroll and Ruppert tech reports at UNC - length(bib[author='ruppert',bibtype="report",institution="north carolina"]) + ##Carroll and Ruppert tech reports at UNC + length(bib[author='ruppert',bibtype="report",institution="north carolina"]) - ## Carroll and Ruppert papers since leaving UNC - length(SearchBib(bib, author='ruppert', date="1987-07/", - .opts = list(match.date = "exact"))) -} + ## Carroll and Ruppert papers since leaving UNC + length(SearchBib(bib, author='ruppert', date="1987-07/", + .opts = list(match.date = "exact"))) -## Carroll and Ruppert papers NOT in the 1990's -\dontrun{ -if (requireNamespace("bibtex")) { - length(SearchBib(bib, author='ruppert', date = "!1990/1999")) - identical(SearchBib(bib, author='ruppert', date = "!1990/1999"), - SearchBib(bib, author='ruppert', year = "!1990/1999")) - table(unlist(SearchBib(bib, author='ruppert', date="!1990/1999")$year)) + ## Carroll and Ruppert papers NOT in the 1990's + length(SearchBib(bib, author='ruppert', date = "!1990/1999")) + identical(SearchBib(bib, author='ruppert', date = "!1990/1999"), + SearchBib(bib, author='ruppert', year = "!1990/1999")) + table(unlist(SearchBib(bib, author='ruppert', date="!1990/1999")$year)) - ## Carroll + Ruppert + Simpson - length(bib[author="Carroll, R. J. and Simpson, D. G. and Ruppert, D."]) + ## Carroll + Ruppert + Simpson + length(bib[author="Carroll, R. J. and Simpson, D. G. and Ruppert, D."]) - ## Carroll + Ruppert OR Carroll + Simpson - length(bib[author=c("Carroll, R. J. and Ruppert, D.", "Carroll, R. J. and Simpson, D. G.")]) + ## Carroll + Ruppert OR Carroll + Simpson + length(bib[author=c("Carroll, R. J. and Ruppert, D.", "Carroll, R. J. and Simpson, D. G.")]) - ## Carroll + Ruppert tech reports at UNC "OR" Carroll and Ruppert JASA papers - length(bib[list(author='ruppert',bibtype="report",institution="north carolina"), - list(author="ruppert",journal="journal of the american statistical association")]) -} + ## Carroll + Ruppert tech reports at UNC "OR" Carroll and Ruppert JASA papers + length(bib[list(author='ruppert',bibtype="report",institution="north carolina"), + list(author="ruppert",journal="journal of the american statistical association")]) } } \seealso{ diff --git a/man/subset-.BibEntry.Rd b/man/subset-.BibEntry.Rd index 6e004ee..a1c4985 100755 --- a/man/subset-.BibEntry.Rd +++ b/man/subset-.BibEntry.Rd @@ -34,7 +34,21 @@ by Biblatex (see \code{\link{BibEntry}}). To clear a field \sQuote{field_name} from an entry use \code{field_name = ""}. } \examples{ -if (requireNamespace("bibtex")) { +bib.text <- "@Manual{mclean2014, + author = {Mathew William McLean}, + title = {Straightforward Bibliography Management in R Using the RefManager Package}, + note = {arXiv: 1403.2036 [cs.DL]}, + year = {2014}, + url = {https://arxiv.org/abs/1403.2036}, +}" +tfile <- tempfile(fileext = ".bib") +writeLines(bib.text, tfile) +bib <- ReadBib(tfile) +bib[1] <- list(c(date = "2014-03", key = "mwm2014")) +bib +unlink(tfile) + +\dontrun{ file.name <- system.file("Bib", "RJC.bib", package="RefManageR") bib <- ReadBib(file.name) print(bib[seq_len(3L)], .opts = list(sorting = "none", bib.style = "alphabetic"))