ropensci / openalexR

Getting bibliographic records from OpenAlex
https://docs.ropensci.org/openalexR/
Other
89 stars 19 forks source link

`search` and `sample` together in `oa_query()` #174

Closed rkrug closed 9 months ago

rkrug commented 9 months ago

Hi I am trying to use sample together with search and the function oa_query() errors out under this condition, although Openex does support it example from below:

The function oa_query_new() has just the sample - search check removed.

r$> oa_query_new(search = params$s_tfc_5, options = list(sample = 100, seed = 13))
[1] "https://api.openalex.org/works?search=%28%27transformative%20change%27%20OR%20%27deliberate%20transformation%2A%27%20OR%20%27transformative%20turn%2A%27%20OR%20%27transition%2A%27%20OR%20%27social-ecological%20change%2A%27%20OR%20%27deep%20change%27%20OR%20%27fundamental%20alteration%27%20OR%20%27profound%20change%27%20OR%20%27profound%20transformation%27%20OR%20%27radical%20transformation%27%20OR%20%27transformational%20change%27%20OR%20%27complete%20change%27%20OR%20%27complete%20transformation%27%20OR%20%27drastic%20change%27%20OR%20%27in-depth%20transformation%27%20OR%20%27progressive%20change%27%20OR%20%27radical%20alteration%27%20OR%20%27radical%20change%27%20OR%20%27revolutionary%20change%27%20OR%20%27significant%20modification%27%20OR%20%27total%20transformation%27%20OR%20%27transformational%20shift%27%20OR%20%27radical%20shift%27%29&sample=100&seed=13"

r$> oa_query_new(search = params$s_tfc_5, options = list(sample = 100, seed = 13)) |> openalexR::oa_request(count_only = TRUE)
$count
[1] 100

$db_response_time_ms
[1] 272

$page
[1] 1

$per_page
[1] 1

I assume, this was introduced in a recent update from OpenAlex.

rkrug commented 9 months ago

Just an addition: aging needs to be set to basic paging = "page" to avoid duplicates.

trangdata commented 9 months ago

Thank you for reporting this update, @rkrug!!! 🌻

With the fix in #175, you can now do:

library(openalexR)
search_terms <- c(
  "\"transformative change\"",
  "\"deliberate transformation\"",
  "\"transformative turn\"",
  "\"social-ecological change\"",
  "\"radical change\"",
  "\"progressive change\"",
  "\"radical alteration\"",
  "\"revolutionary change\"",
  "\"significant modification\"",
  "\"total transformation\"",
  "\"transformational shift\"",
  "\"radical shift\""
) |>
  paste(collapse = "OR")

oa_fetch(
  entity = "works",
  search = search_terms,
  options = list(sample = 100, seed = 13)
)
#> # A tibble: 100 Ă— 37
#>    id     display_name author ab    publication_date relevance_score so    so_id
#>    <chr>  <chr>        <list> <chr> <chr>                      <dbl> <chr> <chr>
#>  1 https… "Growth mec… <df>   "Sca… 2015-07-16                  1.00 Phys… http…
#>  2 https… "WATER, BOT… <df>   "Wat… 1967-04-01                  1.00 Limn… http…
#>  3 https… "Flexible a… <df>   "In … 2007-05-18                  1.00 <NA>  <NA> 
#>  4 https… "Towards a … <df>   "&lt… 2021-12-07                  1.00 <NA>  <NA> 
#>  5 https… "Sustaining… <df>   "OVE… 2009-07-01                  1.00 Rese… http…
#>  6 https… "Promising … <df>   ""    2018-12-28                  1.00 The … http…
#>  7 https…  <NA>        <df>   ""    2003-04-01                  1.00 Surg… http…
#>  8 https… "Does overh… <df>   "Ove… 2012-01-01                  1.00 Arch… http…
#>  9 https… "Effect of … <df>   ""    1990-03-01                  1.00 Indu… http…
#> 10 https… "Temporal c… <df>   "In … 2002-05-01                  1.00 Biol… http…
#> # â„ą 90 more rows
#> # â„ą 29 more variables: host_organization <chr>, issn_l <chr>, url <chr>,
#> #   pdf_url <chr>, license <chr>, version <chr>, first_page <chr>,
#> #   last_page <chr>, volume <chr>, issue <chr>, is_oa <lgl>,
#> #   is_oa_anywhere <lgl>, oa_status <chr>, oa_url <chr>,
#> #   any_repository_has_fulltext <lgl>, language <chr>, grants <list>,
#> #   cited_by_count <int>, counts_by_year <list>, publication_year <int>, …

Created on 2023-10-04 with reprex v2.0.2

rkrug commented 9 months ago

Thanks a lot @trangdata .