-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
show_resources <- function(dataset_name){ | ||
# throw error if name type/format is invalid | ||
check_dataset_name(dataset_name) | ||
|
||
# define query and try API call | ||
query <- list("id" = dataset_name) | ||
content <- try( | ||
phs_GET("package_show", query), | ||
silent = TRUE | ||
) | ||
|
||
# if content contains a 'Not Found Error' | ||
# throw error with suggested dataset name | ||
if (grepl("Not Found Error", content[1])) { | ||
suggest_dataset_name(dataset_name) | ||
} | ||
|
||
# define list of resource IDs and names within dataset | ||
all_ids <- purrr::map_chr(content$result$resources, ~ .x$id) | ||
all_names <- purrr::map_chr(content$result$resources, ~ .x$name) | ||
return_value <- list("id" = all_ids, "names" = all_names) | ||
|
||
return(return_value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
show_resources <- function(dataset_name){ | ||
# throw error if name type/format is invalid | ||
check_dataset_name(dataset_name) | ||
|
||
# define query and try API call | ||
query <- list("id" = dataset_name) | ||
content <- try( | ||
phs_GET("package_show", query), | ||
silent = TRUE | ||
) | ||
|
||
# if content contains a 'Not Found Error' | ||
# throw error with suggested dataset name | ||
if (grepl("Not Found Error", content[1])) { | ||
suggest_dataset_name(dataset_name) | ||
} | ||
|
||
# define list of resource IDs and names within dataset | ||
all_ids <- purrr::map_chr(content$result$resources, ~ .x$id) | ||
all_names <- purrr::map_chr(content$result$resources, ~ .x$name) | ||
return_value <- list("id" = all_ids, "names" = all_names) | ||
|
||
return(return_value) | ||
} |