8181# ' section bellow that can help the extension development.
8282# '
8383# '
84- # ' @param q a `rstac_query` object expressing a STAC query
84+ # ' @param q a `rstac_query` object expressing a STAC query
8585# ' criteria.
8686# '
87- # ' @param res a `httr` `response` object.
88- # ' @param params a `list` with params to add in request.
87+ # ' @param res a `httr` `response` object.
88+ # ' @param simplify_vector a `logical` describing whether length-one nested
89+ # ' lists should be simplified into vectors. Defaults to TRUE. Can also be set
90+ # ' for an entire session via e.g. \code{options(rstac.simplify_vector = FALSE)}.
91+ # ' @param params a `list` with params to add in request.
8992# '
9093# ' @return
9194# ' A `rstac_query` object for `before_request()` and
@@ -108,7 +111,7 @@ before_request <- function(q) {
108111# ' @title Extension development functions
109112# '
110113# ' @rdname extensions
111- after_response <- function (q , res ) {
114+ after_response <- function (q , res , simplify_vector = TRUE ) {
112115 UseMethod(" after_response" , q )
113116}
114117
@@ -124,21 +127,22 @@ parse_params <- function(q, params) {
124127# ' response is in accordance with the allowed status codes and content-types.
125128# ' It returns the parsed content response.
126129# '
127- # ' @param res a `httr` `response` object.
130+ # ' @param res a `httr` `response` object.
128131# '
129132# ' @param status_codes a `character` vector with successful
130133# ' status codes.
131134# '
132135# ' @param content_types a `character` vector with all acceptable
133136# ' responses' content type.
134137# '
135- # ' @param key_message a `character` vector with the JSON keys to show the
138+ # ' @param key_message a `character` vector with the JSON keys to show the
136139# ' requested API message.
137140# '
138141# ' @return
139142# ' The `content_response()` function returns a `list` data structure
140143# ' representing the JSON file received in HTTP response
141- content_response <- function (res , status_codes , content_types , key_message ) {
144+ content_response <- function (res , status_codes , content_types , key_message ,
145+ simplify_vector = TRUE ) {
142146 # convert any json extension
143147 returned_content_type <- httr :: http_type(res )
144148 if (! grepl(content_types , returned_content_type )) {
@@ -256,11 +260,12 @@ set_query_endpoint <- function(q, endpoint, params = NULL) {
256260 q
257261}
258262
259- content_response_json <- function (res ) {
263+ content_response_json <- function (res , simplify_vector = TRUE ) {
260264 content_response(
261265 res = res ,
262266 status_codes = " 200" ,
263267 content_types = " application/.*json" ,
264- key_message = c(" message" , " description" , " detail" )
268+ key_message = c(" message" , " description" , " detail" ),
269+ simplify_vector = simplify_vector
265270 )
266271}
0 commit comments