-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sc_table: Allow json request to be passed as string #36
Conversation
Thank you! I am a little bit of a perfectionist when it comes to "naming things" so I'll have to think about how exactly this should be included in #' @param json path to a json file, which was downloaded via the STATcube GUI ("Open Data API Query").
#' Alternatively, a json string with a class attribute of `"json"`.
sc_table(json, language = NULL, add_totals = TRUE, key = NULL) {
if (!inherits(json, "json"))
json <- readLines(json, warn = FALSE)
# ...
} The recommended way for custom requests is to use |
That sounds like a much more elegant solution indeed but might require some rewriting for the table class, since it involves uses the Another alternative would be to just skip sc_table <- function(json, language = NULL, add_totals = TRUE,
key = NULL) {
...
is_json <- jsonlite::validate(json)
res <- sc_table_json_post(json, language, add_totals, key) %>%
sc_table_class$new(json = ifelse(is_json), file = ifelse(is_json, ...), add_totals = add_totals) |
reimplements #36 with a slightly different approach in regards to naming
I was actually trying to find a regex yesterday that aimed to perform what remotes::install_github("statistikat/STATcubeR@6b63a60")
STATcubeR::sc_table('{"database": "str:database:detouextregsai"}') |
Awesome, nice work! |
Any news on the v0.6 release @GregorDeCillia? Thanks! |
@matmo unfortunately, plans for further development of the package are currently "on-hold" due to time-constraints as @GregorDeCillia has left STAT. |
Currently
sc_table
only allows json files to be used. This is a limitation for certain use cases (when you, e.g. want to dynamically update the query or want to bundle the json query with R code).This commit is a quick fix that allows the user to provide a json query from an R object.
The implementation preserves the current behaviour: If provided, the
json_file
is read in an takes precedence over the newjson
parameter. If nojson_file
is provided the user-suppliedjson
query is sent to the server instead.