1

I'm trying to use the Stack Exchange API to collect all questions under a specific tag using this code:

library(stackr)

df_r_questions <- stack_tags("python","questions", num_pages=1000000, pagesize=100)

However I receive this error:

Error in match.arg(special, c(special_ids, special_no_ids)) : 
  'arg' should be one of “faq”, “related”, “synonyms”, “wikis”, “info”, “moderator-only”, “required”

Any update I should make?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Erik Brole
  • 315
  • 9

1 Answers1

3

I think stack_tags returns information about the tags themselves, not questions with a particular tag. Perhaps you are looking for stack_questions?

library(stackr)
library(tidyverse)

stack_questions(from = '2022-12-21', todate = '2022-12-22', tagged = 'r') %>%
  select(title) %>%
  as_tibble()
#> # A tibble: 30 x 1
#>    title                                                                      
#>    <chr>                                                                     
#>  1 How can one include Js code for rendering KaTeX by reactable in R Shiny?    
#>  2 How to merge 2 vectors alternating indexes?                              
#>  3 Select the first row by group                                            
#>  4 How to sum a variable by group                                           
#>  5 Aggregate / summarize multiple variables per group (e.g. sum, mean)        
#>  6 Arrange by value, only if other conditions are satifisfied                 
#>  7 Select rows were some column is equal to the max value for a group of ma~
#>  8 How to assign correct projection and extent to a raster using terra r pa~
#>  9 there is no package called &amp;quot;png&amp;quot;                      
#> 10 Combine multiple xts objects created by getSymbols                      
#> # ... with 20 more rows

Created on 2022-12-23 with reprex v2.0.2

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Thank you! I would like to collect all questions under a specific tag and I found this option https://stackoverflow.com/questions/49836057/how-to-get-all-questions-related-to-a-tag-using-the-stackr-library but I think it is not working any more – Erik Brole Dec 22 '22 at 15:40
  • `stack_questions` uses the [`/questions`](https://api.stackexchange.com/docs/questions) API method, which has a `tagged` field. Instead of fetching questions and filtering out those without a particular tag, you can use that field directly. I'm not familiar with R, however, so I don't know how it should look like. – double-beep Dec 23 '22 at 10:13
  • @double-beep thanks - amended. The `tagged` field isn't documented in the R port, but does work. The API seems to limit the user to 25 pages per request unless they have an access token, so the OP will need one to get _all_ tagged questions. – Allan Cameron Dec 23 '22 at 10:47
  • 1
    There's a difference between an access token and an *API key*. The key increases daily quota from 300 to 10,000 while an access token is needed to perform write actions on behalf of a user! The OP will need a key. To do that, they need to register an app. – double-beep Dec 23 '22 at 10:56
  • 1
    You may also specify `pagesize` to 100 (if it's not already the default) to get more results per page. – double-beep Dec 23 '22 at 10:58