Skip to content

Instantly share code, notes, and snippets.

@philerooski
Last active October 7, 2019 23:31
Show Gist options
  • Save philerooski/2b182d383d577e98bda5265d1b8a1130 to your computer and use it in GitHub Desktop.
Save philerooski/2b182d383d577e98bda5265d1b8a1130 to your computer and use it in GitHub Desktop.
library(synapser)
library(tidyverse)
PROJECT_ID <- "syn12030321"
UDALL_USERS <- "syn18691020"
AT_HOME_PD_USERS <- "syn16786935"
get_users <- function(user_table_id) {
user_table <- as_tibble(synTableQuery(paste(
"SELECT guid FROM", user_table_id, "WHERE status LIKE 'Success%'"))$asDataFrame())
return(user_table)
}
update_tables <- function(project) {
tables <- synGetChildren(project, includeTypes = list("table"))$asList()
udall_users <- get_users(UDALL_USERS)
at_home_pd_users <- get_users(AT_HOME_PD_USERS)
substudy_users <- bind_rows(udall_users, at_home_pd_users)
purrr::map(tables, function(t) {
table_id <- t$id
table <- synTableQuery(paste("select * from", table_id))$asDataFrame()
if (has_name(table, "externalId")) {
affected_rows <- table %>%
semi_join(substudy_users, by = c("externalId" = "guid"))
if (has_name(affected_rows, "userSharingScope")) {
snapshot <- synRestPOST(paste0("/entity/", table_id, "/table/snapshot"), body = "{}")
affected_rows <- affected_rows %>%
mutate(userSharingScope = "ALL_QUALIFIED_RESEARCHERS")
synStore(Table(table_id, affected_rows))
}
}
})
}
main <- function() {
synLogin()
update_tables(PROJECT_ID)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment