Skip to content

Commit

Permalink
create show_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-hull committed May 6, 2024
1 parent e8e5e09 commit 535c459
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions R/get_resources.R
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)
}
24 changes: 24 additions & 0 deletions R/show_resources.R
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)
}

0 comments on commit 535c459

Please sign in to comment.