Skip to content
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

Integrate generic pagination support for list methods #95

Open
davecap opened this issue Aug 4, 2018 · 0 comments
Open

Integrate generic pagination support for list methods #95

davecap opened this issue Aug 4, 2018 · 0 comments

Comments

@davecap
Copy link
Member

davecap commented Aug 4, 2018

List resource methods such as Object.all(), Vault.all() and others currently do not have any built-in pagination support. The following snippet shows how it can be done. Combining lists of data frames requires flattening them first (similar to how we currently paginate dataset query results). Nested keys are flattened (i.e. i[user][email] becomes i[user.email]). Maybe there is a way around this...

require("solvebio")
solvebio::login()
        
# Retrieves objects within a specific vault.
paginateObjects <- function(vault_id, env = solvebio:::.solveEnv, ...) {
    # Retrieve the first page of results
    params <- list(...)
    params$vault_id <- vault_id
    params$env <- env
    params$page <- 1

    response <- do.call(Object.all, params)
    # Flatten the results in order to merge them
    # NOTE: This will flatten nested keys with dot-separated paths.
    #       For example: i$user$email will be i$user.email
    objects <- jsonlite::flatten(response$data)       
                                                      
    # Retrieve and merge subsequent pages of results  
    while (!is.null(response$links[['next']])) {          
        params$page <- params$page + 1          
        response <- do.call(Object.all, params) 
        objects <- dplyr::bind_rows(objects, jsonlite::flatten(response$data))
    }                                           
    
    return(objects)
}                                      

vault <- Vault.get_personal_vault()
df <- paginateObjects(vault_id=vault$id, object_type="dataset")
print(df$full_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant