Skip to content

Commit

Permalink
fix #82, fix #83, fix #102 cr_search, cr_search_free and crosscite de…
Browse files Browse the repository at this point in the history
…funct now

removed their test files as well
also made all text mining fxns deprecated, to notify users of the new package and of future defunctifying #122
bumped patch version
  • Loading branch information
sckott committed Oct 21, 2016
1 parent df28a46 commit a8e7496
Show file tree
Hide file tree
Showing 29 changed files with 298 additions and 647 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: Client for various 'CrossRef' APIs, including 'metadata' search
(including 'bibtex', 'citeproc-json', 'rdf-xml', etc.), convert 'DOIs'
to 'PMIDs', and 'vice versa', get citations for 'DOIs', and get links to
full text of articles when available.
Version: 0.5.8.9400
Version: 0.5.9.9100
License: MIT + file LICENSE
Authors@R: c(
person("Scott", "Chamberlain", role = c("aut", "cre"), email = "myrmecocystus@gmail.com"),
Expand Down
4 changes: 2 additions & 2 deletions R/cr_cn.r
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#' @param raw (logical) Return raw text in the format given by \code{format}
#' parameter. Default: FALSE
#' @template moreargs
#' @details See \url{http://www.crosscite.org/cn/} for more info on the Crossref
#' Content Negotiation API service.
#' @details See \url{http://citation.crosscite.org/docs.html} for more info
#' on the Crossref Content Negotiation API service.
#'
#' DataCite DOIs: Some values of the \code{format} parameter won't work with
#' DataCite DOIs, i.e. "citeproc-json", "crossref-xml", "crossref-tdm",
Expand Down
12 changes: 2 additions & 10 deletions R/cr_fundref.r
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,10 @@
#' cr_funders_('10.13039/100000001', works = TRUE, cursor = "*",
#' cursor_max = 300, limit = 100, parse = TRUE)
#' }
`cr_fundref` <- function(dois = NULL, query = NULL, filter = NULL, offset = NULL,
`cr_funders` <- function(dois = NULL, query = NULL, filter = NULL, offset = NULL,
limit = NULL, sample = NULL, sort = NULL, order = NULL, facet=FALSE,
works = FALSE, cursor = NULL, cursor_max = 5000, .progress="none", ...) {

.Deprecated(
msg =
"function name changing to cr_funders in the next version\nboth work for now"
)
args <- prep_args(query, filter, offset, limit, sample, sort,
order, facet, cursor)
if (length(dois) > 1) {
Expand Down Expand Up @@ -137,11 +133,7 @@
}

#' @export
#' @rdname cr_fundref
`cr_funders` <- `cr_fundref`

#' @export
#' @rdname cr_fundref
#' @rdname cr_funders
`cr_funders_` <- function(dois = NULL, query = NULL, filter = NULL,
offset = NULL, limit = NULL, sample = NULL, sort = NULL, order = NULL,
facet=FALSE, works = FALSE, cursor = NULL, cursor_max = 5000,
Expand Down
96 changes: 7 additions & 89 deletions R/cr_search.r
Original file line number Diff line number Diff line change
@@ -1,93 +1,11 @@
#' Search the CrossRef Metatdata API.
#'
#'
#' @export
#'
#' @param query Query terms.
#' @param doi Search by a single DOI or many DOIs.
#' @param page Page to return from results.
#' @param rows Number of records to return.
#' @param sort Sort either by "score" or "year".
#' @param year Year to search.
#' @param type Record type, e.g., "Journal Article" or "Journal Issue"
#' @param ... Named parameters passed on to \code{\link[httr]{GET}}
#'
#' @details See \url{http://search.labs.crossref.org/help/api} for more
#' info on this Crossref API service.
#' @seealso \code{\link{cr_r}}, \code{\link{cr_citation}},
#' \code{\link{cr_search_free}}
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}
#' @examples \dontrun{
#' cr_search(query = c("renear", "palmer"))
#'
#' # limit to 4 results
#' cr_search(query = c("renear", "palmer"), rows = 4)
#'
#' # get more results than standard
#' cr_search(query = c("renear", "palmer"), rows = 40)
#'
#' # sort results by score
#' cr_search(query = c("renear", "palmer"), rows = 10, sort = "score")
#'
#' # sort results by year
#' cr_search(query = c("renear", "palmer"), rows = 10, sort = "year")
#'
#' # get results for a certain year
#' cr_search(query = c("renear", "palmer"), year = 2010)
#'
#' # search by a single DOI
#' cr_search(doi = "10.1890/10-0340.1")
#'
#' # search for many DOI's
#' # find all the records of articles from a journal ISBN
#' cr_search(query = "1461-0248", type="Journal Article")
#'
#' # curl stuff
#' library('httr')
#' cr_search(doi = "10.1890/10-0340.1", config=verbose())
#' cr_search(query = c("renear", "palmer"), rows = 40, config=progress())
#' }

`cr_search` <- function(query=NULL, doi=NULL, page=NULL, rows=NULL, sort=NULL,
year=NULL, type=NULL, ...) {

.Deprecated(
package = "rcrossref",
msg = "cr_search is deprecated, and will be removed in next version, see cr_works et al."
#' @rdname cr_search-defunct
#' @keywords internal
`cr_search` <- function(...) {
.Defunct(
package = "rcrossref",
msg = "Removed - see cr_works(), cr_journals(), etc. for similar functionality"
)
url <- "http://search.crossref.org/dois"
if (!is.null(doi)) {
doi <- as.character(doi)
}
if (is.null(doi)) {
cr_search_GET(url, query, page, rows, sort, year, type, ...)
} else {
ldply(doi, function(z) cr_search_GET(url, x = z, page, rows, sort,
year, type, ...))
}
}

cr_search_GET <- function(url, x, page, rows, sort, year, type, ...){
if (!is.null(x)) {
if (length(x) > 1) x <- paste0(x, collapse = " ")
}
args <- cr_compact(list(q = x, page = page, rows = rows,
sort = sort, year = year, type = type))
tt <- GET(url, query = args, make_rcrossref_ua(), ...)
stop_for_status(tt)
res <- ct_utf8(tt)
tmp <- jsonlite::fromJSON(res)
if (NROW(tmp) == 0) {
NULL
} else {
col_classes(
tmp,
c("character","numeric","integer","character",
"character","character","numeric")
)
}
}

asnum <- function(x){
tmp <- tryCatch(as.numeric(x), warning = function(w) w)
if (inherits(tmp, "simpleWarning")) x else tmp
}
53 changes: 7 additions & 46 deletions R/cr_search_free.r
Original file line number Diff line number Diff line change
@@ -1,50 +1,11 @@
#' Search the CrossRef Metatdata for DOIs using free form references.
#'
#' @export
#'
#' @param query Reference query; a character vector of length 1 or greater,
#' comma-separated of course.
#' @param url Base url for the Crossref metadata API.
#'
#' @details Have to have at least three terms in each search query.
#' @seealso \code{\link{cr_search}}, \code{\link{cr_r}},
#' \code{\link{cr_citation}}
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}
#' @examples \dontrun{
#' # search with title, author, year, and journal
#' cr_search_free(query = "Piwowar Sharing Detailed Research Data Is
#' Associated with Increased Citation Rate PLOS one 2007")
#'
#' cr_search_free(query="Renear 2012") # too few words, need at least 3
#'
#' # multiple queries
#' cr_search_free(query=c("Renear 2012","Piwowar sharing data PLOS one"))
#'
#' # Get a DOI and get the citation using cr_search
#' doi <- cr_search_free(query="Piwowar sharing data PLOS one")$doi
#' cr_search(doi = doi)
#'
#' # Queries can be quite complex too
#' cr_search_free("M. Henrion, D. J. Mortlock, D. J. Hand, and A. Gandy,
#' \"A Bayesian approach to star-galaxy classification,\" Monthly Notices of
#' the Royal Astronomical Society, vol. 412, no. 4, pp. 2286-2302, Apr. 2011.")
#'
#' # Lots of queries
#' queries <- c(
#' "Piwowar sharing data PLOS one", "Priem Scientometrics 2.0 social web",
#' "William Gunn A Crosstalk Between Myeloma Cells",
#' "karthik ram Metapopulation dynamics override local limits")
#' cr_search_free(queries)
#' }

`cr_search_free` <- function(query, url = "http://search.crossref.org/links") {
.Deprecated(package = "rcrossref",
msg = "cr_search_free is deprecated, and will be removed in next version, see cr_works et al.")
tt <- POST(
url,
config = c(content_type_json(), accept_json()),
body = jsonlite::toJSON(query))
stop_for_status(tt)
res <- ct_utf8(tt)
fromJSON(res)$results
#' @rdname cr_search_free-defunct
#' @keywords internal
`cr_search_free` <- function(...) {
.Defunct(
package = "rcrossref",
msg = "Removed - see cr_works(), cr_journals(), etc. for similar functionality"
)
}
55 changes: 6 additions & 49 deletions R/crosscite.R
Original file line number Diff line number Diff line change
@@ -1,54 +1,11 @@
#' Crosscite - citation formatter
#'
#' @export
#' @param dois Search by a single DOI or many DOIs.
#' @param style a CSL style (for text format only). See
#' \code{\link{get_styles}} for options. Default: apa. If there's a style that
#' CrossRef doesn't support you'll get a \code{(500) Internal Server Error}
#' @param locale Language locale. See \code{?Sys.getlocale}
#' @template moreargs
#' @details See \url{http://www.crosscite.org/cn/} for more info on the
#' Crossref Content Negotiation API service.
#'
#' This function is now deprecated. It will be removed in the next version
#' of this package. Use \code{\link{cr_cn}} instead.
#'
#' @examples \dontrun{
#' crosscite("10.5284/1011335")
#' crosscite(c('10.5169/SEALS-52668','10.2314/GBV:493109919',
#' '10.2314/GBV:493105263', '10.2314/GBV:487077911',
#' '10.2314/GBV:607866403'))
#' }

`crosscite` <- function(dois, style = 'apa', locale = "en-US",
.progress = "none", ...) {

.Deprecated(
new = "cr_cn",
package = "rcrossref",
msg = "crosscite is deprecated - will be removed in next version, use cr_cn"
#' @rdname crosscite-defunct
#' @keywords internal
`crosscite` <- function(...) {
.Defunct(
package = "rcrossref",
msg = "Removed - see cr_works(), cr_journals(), etc. for similar functionality"
)
if (length(dois) > 1) {
llply(dois, function(z, ...) {
out <- try(ccite(z, style, locale, ...), silent=TRUE)
if ("try-error" %in% class(out)) {
warning(
paste0("Failure in resolving '", z, "'. See error detail in results.")
)
out <- list(doi=z, error=out[[1]])
}
return(out)
}, .progress=.progress)
} else {
ccite(dois, style, locale, ...)
}
}

ccite <- function(doi, style, locale, ...) {
args <- cr_compact(list(doi = doi, style = style, locale = locale))
res <- GET(ccurl(), query = args, make_rcrossref_ua(), ...)
stop_for_status(res)
gsub("\n", "", ct_utf8(res))
}

ccurl <- function() "http://crosscite.org/citeproc/format"
47 changes: 39 additions & 8 deletions R/deprecated_defunct.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
#' These functions still work but will be removed (defunct) in the next version.
#'
#' \itemize{
#' \item \code{\link{cr_search}}: The functionality of this function can
#' be achieved with the new Crossref API. See functions \code{\link{cr_works}}
#' et al.
#' \item \code{\link{cr_search_free}}: The functionality of this function can
#' be achieved with the new Crossref API. See functions \code{\link{cr_works}}
#' et al.
#' \item \code{\link{crosscite}}: The functionality of this function can be
#' achieved with \code{\link{cr_cn}}
#' \item \code{\link{cr_ft_text}}: This function and other text mining
#' functions are being incorporated in a new package \code{crminer}.
#' \item \code{\link{cr_ft_links}}: This function and other text mining
#' functions are being incorporated in a new package \code{crminer}.
#' \item \code{\link{cr_ft_pdf}}: This function and other text mining
#' functions are being incorporated in a new package \code{crminer}.
#' \item \code{\link{cr_ft_plain}}: This function and other text mining
#' functions are being incorporated in a new package \code{crminer}.
#' \item \code{\link{cr_ft_text}}: This function and other text mining
#' functions are being incorporated in a new package \code{crminer}.
#' \item \code{\link{cr_ft_xml}}: This function and other text mining
#' functions are being incorporated in a new package \code{crminer}.
#' \item \code{\link{as.tdmurl}}: This function and other text mining
#' functions are being incorporated in a new package \code{crminer}.
#' \item \code{\link{extract_xpdf}}: This function and other text mining
#' functions are being incorporated in a new package \code{crminer}.
#' }
#'
#' @name rcrossref-deprecated
Expand All @@ -28,7 +36,30 @@ NULL
#' \item \code{\link{pmid2doi}} and \code{\link{doi2pmid}}: The API behind
#' these functions is down for good, see \code{\link{id_converter}} for
#' similar functionality.
#' \item \code{\link{cr_search}}: The functionality of this function can
#' be achieved with the new Crossref API. See functions \code{\link{cr_works}}
#' et al.
#' \item \code{\link{cr_search_free}}: The functionality of this function can
#' be achieved with the new Crossref API. See functions \code{\link{cr_works}}
#' et al.
#' \item \code{\link{crosscite}}: The functionality of this function can be
#' achieved with \code{\link{cr_cn}}
#' \item \code{\link{cr_fundref}}: Crossref changed their name "fundref"
#' to "funders", so we've changed our function, see \code{\link{cr_funders}}
#' }
#'
#' @name rcrossref-defunct
NULL

#' fundref
#'
#' @export
#' @rdname cr_fundref-defunct
#' @keywords internal
`cr_fundref` <- function(...) {
.Defunct(
new = "cr_funders",
package = "rcrossref",
msg = "Removed - see cr_funders()"
)
}
3 changes: 2 additions & 1 deletion R/rcrossref-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#' rcrossref interacts with the main Crossref metadata search API at
#' \url{https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md},
#' the old metadata search API at \url{http://search.labs.crossref.org/}, their
#' DOI Content Negotiation service at \url{http://www.crosscite.org/cn/}, and
#' DOI Content Negotiation service at
#' \url{http://citation.crosscite.org/docs.html}, and
#' the \emph{Text and Data Mining} project \url{http://tdmsupport.crossref.org/}
#'
#' @section Deprecated and Defunct:
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The following functions all use the [CrossRef API](https://github.com/CrossRef/r
### Look up funder information

```{r}
cr_fundref(query = "NSF")
cr_funders(query = "NSF")
```

### Check the DOI minting agency
Expand Down
Loading

0 comments on commit a8e7496

Please sign in to comment.