diff --git a/R/fetch.R b/R/fetch.R index 0751b8fd..18751db4 100644 --- a/R/fetch.R +++ b/R/fetch.R @@ -182,10 +182,19 @@ check_dataset <- dataset } +# return available datasets sorted my descending modification time +# i.e. newest first available_datasets <- function(conn=NULL, ...) { conn=neuprint_login(conn) ds=neuprint_datasets_memo(conn=conn, ...) - datasets <- names(ds) - if(length(datasets)==0) return(NULL) else datasets + if(length(ds)==0) return(NULL) + # find last modification times, filling missing values with na + lastmod = sapply(ds, function(x) { + lm = x[["last-mod"]] + if (nzchar(lm)) lm else NA_character_ + }) + # sort to return newest first + lastmod=sort(lastmod, na.last = TRUE, decreasing = TRUE) + datasets=names(lastmod) + datasets } -