Skip to content

Commit

Permalink
Increase safety of create_dataset (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
allaway authored Feb 9, 2024
1 parent 3f110ac commit f639164
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions R/access_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,25 @@ grant_specific_file_access <- function(principal_id, entity_ids, create_dataset
}

if(create_dataset){
dataset <- .syn$store(
synapseclient$Dataset(
name=dataset_name,
parent=project_id,
dataset_items=dataset_items)
)

# Add/remove specific Synapse IDs to/from the Dataset

.syn$setPermissions(entity = dataset$properties$id,
principalId = principal_id,
accessType = list("READ","DOWNLOAD"))


message(glue::glue('{emoji::emoji("thumbsup")} Dataset created at {dataset$properties$id}'))
tryCatch({
# First attempt with addAnnotationColumns = TRUE
dataset <- .syn$store(synapseclient$Dataset(name = dataset_name,
parent = project_id, dataset_items = dataset_items, addAnnotationColumns = TRUE))
message(glue::glue("{emoji::emoji(\"thumbsup\")} Dataset created with annotation columns at {dataset$properties$id}"))
}, error = function(e) {
# If error, retry with addAnnotationColumns = FALSE
dataset <- .syn$store(synapseclient$Dataset(name = dataset_name,
parent = project_id, dataset_items = dataset_items, addAnnotationColumns = FALSE))
.syn$setPermissions(entity = dataset$properties$id, principalId = principal_id,
accessType = list("READ", "DOWNLOAD"))
message(glue::glue("{emoji::emoji(\"warning\")} Dataset created without annotation columns at {dataset$properties$id}. Annotation columns will need to be added manually."))
})
}

message(glue::glue('{emoji::emoji("astonished")} Principal {principal_id} added to {length(entity_ids)} entities'))

#TODO: set schema programmatically? might be easier to add annotations to schema in web client as needed to support principal_id...
## Note Dec 2023; schema is automatically defined unless there is an error caused by the way synapse detects annotation schemas, e.g. a type collision that causes duplicate columns with the same name.

}

0 comments on commit f639164

Please sign in to comment.