@@ -43,7 +43,7 @@ resolve_name <- function(x) {
4343 res_names <- strsplit(x , " /" , fixed = TRUE )[[1 ]]
4444 if (length(res_names ) > 2 ) {
4545 cli :: cli_abort(
46- " {.arg name} has {length(res_names)} components instead of 2 ."
46+ " {.arg name} is not correctly formatted ."
4747 )
4848 }
4949 } else {
@@ -110,17 +110,20 @@ download_file <- function(zip_url, token = NULL, file, size_limit) {
110110ns_metadata <- function (name , collection = FALSE ) {
111111 rlang :: check_installed(" cli" )
112112 net_ident <- resolve_name(name )
113- path <- sprintf(" api/net/%s" , net_ident [[1 ]])
114- collection_url <- sprintf(" https://networks.skewed.de/net/%s" , net_ident [[1 ]])
113+ path <- sprintf(" api/net/%s" , net_ident [[" collection" ]])
114+ collection_url <- sprintf(
115+ " https://networks.skewed.de/net/%s" ,
116+ net_ident [[" collection" ]]
117+ )
115118 resp <- make_request(path )
116119 raw <- httr2 :: resp_body_json(resp )
117120 class(raw ) <- c(" ns_meta" , class(raw ))
118121 raw [[" is_collection" ]] <- collection
119- raw [[" collection_name" ]] <- net_ident [[1 ]]
122+ raw [[" collection_name" ]] <- net_ident [[" collection " ]]
120123 if (collection ) {
121124 return (raw )
122125 } else if (
123- net_ident [[1 ]] == net_ident [[2 ]] &&
126+ net_ident [[" collection " ]] == net_ident [[" network " ]] &&
124127 length(unlist(raw $ nets )) > 1 &&
125128 ! collection
126129 ) {
@@ -130,10 +133,10 @@ ns_metadata <- function(name, collection = FALSE) {
130133 " i" = " see {.url {collection_url}}"
131134 )
132135 )
133- } else if (net_ident [[1 ]] == net_ident [[2 ]]) {
136+ } else if (net_ident [[" collection " ]] == net_ident [[" network " ]]) {
134137 return (raw )
135138 } else {
136- idx <- which(unlist(raw [[" nets" ]]) == net_ident [[2 ]])
139+ idx <- which(unlist(raw [[" nets" ]]) == net_ident [[" network " ]])
137140 if (length(idx ) == 0 ) {
138141 cli :: cli_abort(
139142 c(
@@ -142,7 +145,7 @@ ns_metadata <- function(name, collection = FALSE) {
142145 )
143146 )
144147 }
145- raw [[" analyses" ]] <- raw [[" analyses" ]][[net_ident [[2 ]]]]
148+ raw [[" analyses" ]] <- raw [[" analyses" ]][[net_ident [[" network " ]]]]
146149 raw [[" nets" ]] <- raw [[" nets" ]][idx ]
147150 raw
148151 }
@@ -164,14 +167,15 @@ ns_df <- function(name, token = NULL, size_limit = 1) {
164167 }
165168 meta <- name
166169 net_ident <- c(meta [[" collection_name" ]], meta [[" nets" ]])
170+ names(net_ident ) <- c(" collection" , " network" )
167171 } else {
168172 cli :: cli_abort(" {.arg name} must be a string or a `ns_meta` object." )
169173 }
170174
171175 zip_url <- sprintf(
172176 " net/%s/files/%s.csv.zip" ,
173- net_ident [[1 ]],
174- net_ident [[2 ]]
177+ net_ident [[" collection " ]],
178+ net_ident [[" network " ]]
175179 )
176180
177181 temp <- tempfile(fileext = " zip" )
0 commit comments