1919# ' You can open your `.Renviron` file calling `file.edit("~/.Renviron")`.
2020# ' Save the file and restart your R session. To stop sharing your email
2121# ' when using rcrossref, delete it from your `.Renviron` file.
22+ # ' @param .flatten Simplify open access evidence output. If `TRUE` it
23+ # ' transforms the nested column oa_locations so that each open access
24+ # ' evidence variable has its own column and each row represents a
25+ # ' single full-text.
26+ # ' Following these basic principles of "Tidy Data" makes data analysis
27+ # ' and export as a spreadsheet more straightforward.
2228# ' @param .progress Shows the \code{plyr}-style progress bar.
2329# ' Options are "none", "text", "tk", "win", and "time".
2430# ' See \code{\link[plyr]{create_progress_bar}} for details
3743# ' over AcceptedVersion), then more authoritative repositories (PubMed Central
3844# ' over CiteSeerX). \cr
3945# ' \code{oa_locations} \tab list-column of all the OA locations. \cr
46+ # ' \code{oa_locations_embargoed} \tab list-column of
47+ # ' locations expected to be available in the future based on
48+ # ' information like license metadata and journals'
49+ # ' delayed OA policies \cr
4050# ' \code{data_standard} \tab Indicates the data collection approaches used
4151# ' for this resource. \code{1} mostly uses Crossref for hybrid detection.
4252# ' \code{2} uses a more comprehensive hybrid detection methods. \cr
6878# ' name and author role \code{sequence}), if available. \cr
6979# ' }
7080# '
71- # ' The columns \code{best_oa_location} and \code{oa_locations}
72- # ' are list-columns that contain useful metadata about the OA sources
73- # ' found by Unpaywall. The \code{best_oa_location} only lists non-empty subfields.
81+ # ' The columns \code{best_oa_location}. \code{oa_locations} and
82+ # ' \code{oa_locations_embargoed} are list-columns that contain
83+ # ' useful metadata about the OA sources found by Unpaywall.
84+ # '
85+ # ' If \code{.flatten = TRUE} the list-column \code{oa_locations} will be
86+ # ' restructured in a long format where each OA fulltext is represented by
87+ # ' one row.
7488# '
7589# ' These are:
7690# '
95109# ' \cr
96110# ' }
97111# '
98- # nolint end
99- # ' To unnest list-columns, you want to use tidyr's unnest function
100- # ' \code{\link[tidyr]{unnest}}.
101- # '
102112# ' Note that Unpaywall schema is only informally described.
103113# ' Check also \url{https://unpaywall.org/data-format}.
104114
105115# ' @examples \dontrun{
106116# ' oadoi_fetch("10.1038/nature12373", email = "name@example.com")
107117# ' oadoi_fetch(dois = c("10.1016/j.jbiotec.2010.07.030",
108118# ' "10.1186/1471-2164-11-245"), email = "name@example.com")
119+ # ' # flatten OA evidence
120+ # ' roadoi::oadoi_fetch(dois = c("10.1186/s12864-016-2566-9",
121+ # ' "10.1103/physreve.88.012814",
122+ # ' "10.1093/reseval/rvaa038"),
123+ # ' email = "najko.jahn@gmail.com", .flatten = TRUE)
124+ # '
109125# ' }
110126# '
111127# ' @export
112128oadoi_fetch <-
113129function (dois = NULL ,
114130email = Sys.getenv(" roadoi_email" ),
115- .progress = " none" ) {
131+ .progress = " none" ,
132+ .flatten = FALSE ) {
116133# input validation
117134 stopifnot(! is.null(dois ))
118135# remove empty characters
@@ -129,8 +146,20 @@ oadoi_fetch <-
129146.call = FALSE
130147 )
131148# Call API for every DOI, and return results as tbl_df
132- plyr :: llply(dois ,oadoi_fetch_ ,email ,.progress = .progress ) %> %
149+ req <- plyr :: llply(dois ,oadoi_fetch_ ,email ,.progress = .progress ) %> %
133150dplyr :: bind_rows()
151+ if (.flatten == TRUE ){
152+ out <- req %> %
153+ dplyr :: select(
154+ - .data $ best_oa_location ,
155+ - .data $ authors ,
156+ - .data $ oa_locations_embargoed
157+ ) %> %
158+ tidyr :: unnest(.data $ oa_locations ,keep_empty = TRUE )
159+ }else {
160+ out <- req
161+ }
162+ return (out )
134163 }
135164
136165# ' Get open access status information.
@@ -178,7 +207,7 @@ oadoi_fetch_ <- function(doi = NULL, email = NULL) {
178207
179208# error if nothing could be found and return meaningful message
180209if (httr :: status_code(resp )!= 200 ) {
181- stop (
210+ warning (
182211 sprintf(
183212" Unpaywall request failed [%s]\n %s" ,
184213httr :: status_code(resp ),
@@ -206,6 +235,7 @@ parse_oadoi <- function(req) {
206235doi = req $ doi ,
207236best_oa_location = list (oa_lct_parser(req $ best_oa_location )),
208237oa_locations = list (tibble :: as_tibble(req $ oa_locations )),
238+ oa_locations_embargoed = list (tibble :: as_tibble(req $ oa_locations_embargoed )),
209239data_standard = req $ data_standard ,
210240is_oa = req $ is_oa ,
211241is_paratext = req $ is_paratext ,