Skip to content

Commit fc789de

Browse files
committed
vignette updates
1 parent c7791f0 commit fc789de

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

vignettes/citation-networks.Rmd.orig

+6-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ pat_lst <- unnest_pv_data(pv_out$data, pk = "patent_id")
4747
citing_query <- qry_funs$eq(patent_id = patent_ids)
4848
cited_query <- qry_funs$eq(citation_patent_id = patent_ids)
4949

50-
# Create a list of fields to pull from the API. Note that, with a recent API chanage,
51-
# these aren't the only fields we receive back from the API
50+
# Create a list of fields to pull from the API. Note that, with a recent chanage
51+
# to the R package, these aren't the only fields we'll receive back from the API.
52+
# This is due to the way that the API's paging works now. There is more about this
53+
# in the [Result Set Paging](result-set-paging.html) vignette.
5254
fields <- c(
5355
"patent_id",
5456
"citation_patent_id"
@@ -64,7 +66,7 @@ res2 <- search_pv(cited_query,
6466
endpoint = "patent/us_patent_citation", method = "POST", size = 1000
6567
)
6668

67-
# Unnest the data found in the two lists of columns
69+
# Unnest the data found in the three lists of columns
6870
# (citation_sequence being a field we didn't request)
6971
res_lst <- unnest_pv_data(res$data, pk = "patent_id")
7072
res_lst
@@ -88,7 +90,7 @@ pat_title <- function(title, number) {
8890
edges <-
8991
res_lst$us_patent_citations %>%
9092
semi_join(x = ., y = ., by = c("citation_patent_id" = "patent_id")) %>%
91-
select(patent_id, citation_patent_id) %>% # discard citation_sequence we didn't ask for
93+
select(-citation_sequence) %>% # discard citation_sequence that we don't need here
9294
set_colnames(c("from", "to"))
9395

9496
nodes <-

vignettes/getting-started.Rmd.orig

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ Let's start with a basic example of how to use the package's primary function, `
2626
```{r}
2727
library(patentsview)
2828

29+
fields <- c("patent_id", "patent_date", "patent_title")
30+
2931
search_pv(
3032
query = '{"_gte":{"patent_date":"2007-01-01"}}',
31-
endpoint = "patent"
33+
endpoint = "patent", fields = fields
3234
)
3335
```
3436

@@ -102,10 +104,12 @@ By default, `search_pv()` returns 1,000 records per page and only gives you the
102104
You can download all pages of output in one call by setting `all_pages = TRUE`. This will set `size` equal to 1,000 and loop over all pages of output:
103105

104106
```{r}
107+
fields <- c("patent_id", "inventors.inventor_name_last", "inventors.inventor_name_first")
105108
search_pv(
106109
query = qry_funs$eq(inventors.inventor_name_last = "Chambers"),
107-
all_pages = TRUE, size = 1000
110+
all_pages = TRUE, size = 1000, fields = fields
108111
)
112+
109113
```
110114
See the [result set paging vignette](result-set-paging.html) for information on custom paging.
111115

vignettes/state-of-the-api.Rmd

+48
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,54 @@ but the build will silently fail on r-universe. Don't ask how I know that.
504504
there isn't the 100,000 row limitation now. The API's ```after``` is now exposed
505505
in search_pv() so users could do their own paging. See the new [paging vignette](result-set-paging.html)
506506
507+
## Odd Demo
508+
Here we demonstrate a weird interaction between the API and R package when no sort parmeter
509+
is specified.
510+
511+
```{r}
512+
fields <- c("patent_id", "patent_date", "patent_title")
513+
514+
search_pv(
515+
query = '{"_gte":{"patent_date":"2007-01-01"}}',
516+
endpoint = "patent", fields = fields
517+
)
518+
```
519+
520+
Note that the first patent_date returned above is "2020-04-21" and that what gets
521+
sent to the API is `&s=[]&o=`
522+
523+
```{r}
524+
url <- httr2::last_request()$url
525+
cat(utils::URLdecode(url))
526+
```
527+
528+
529+
Now we'll send in our own GET with `&s=&o` to see that the API return is different,
530+
seemingly applying a default sort?
531+
532+
```{r}
533+
library(httr2)
534+
535+
url <- sub("&s=\\[\\]", "&s=", url)
536+
cat(utils::URLdecode(url))
537+
api_key <- Sys.getenv("PATENTSVIEW_API_KEY")
538+
539+
req <- httr2::request(url) |>
540+
httr2::req_method("GET")
541+
542+
resp <- req |>
543+
httr2::req_user_agent("https://github.com/ropensci/patentsview") |>
544+
httr2::req_retry(max_tries = 20) |> # automatic 429 Retry-After
545+
httr2::req_headers("X-Api-Key" = api_key, .redact = "X-Api-Key") |>
546+
httr2::req_perform()
547+
548+
json <- httr2::last_response() |> httr2::resp_body_json()
549+
json$patents[[1]]
550+
551+
```
552+
For a while POSTs and GETs behaved differently when a sort wasn't specified. Currently
553+
an API bug prevents seeing what the behavior is on POSTS.
554+
507555
[^1]: Observation sent to the API team.
508556
[^2]: Observation sent to the API team.
509557
[^3]: There isn't a data dictionary for the API so I suggested they create one.

0 commit comments

Comments
 (0)