views.Rmd
A view is a view of all entities (File, Folder, Project, Table, Docker Repository, View) within one or more Projects or Folders. Views can:
Preliminaries:
library(synapser)
##
## TERMS OF USE NOTICE:
## When using Synapse, remember that the terms and conditions of use require that you:
## 1) Attribute data contributors when discussing these data or results from these data.
## 2) Not discriminate, identify, or recontact individuals or groups represented by the data.
## 3) Use and contribute only data de-identified to HIPAA standards.
## 4) Redistribute data only under these same terms of use.
synLogin()
## Welcome, migrationAdmin!
## NULL
# Create a new project
# use hex_digits to generate random string
hex_digits <- c(as.character(0:9), letters[1:6])
projectName <- sprintf("My unique project %s", paste0(sample(hex_digits, 32, replace = TRUE), collapse = ""))
project <- Project(projectName)
project <- synStore(project)
# Create some files
filePath <- tempfile()
connection <- file(filePath)
writeChar("this is the content of the first file", connection, eos = NULL)
close(connection)
file <- File(path = filePath, parent = project)
file <- synStore(file)
## ################################################## Uploading file to Synapse storage ##################################################
Uploading [--------------------]0.00% 0.0bytes/37.0bytes filee31f0181c2
Uploading [####################]100.00% 37.0bytes/37.0bytes (31.6bytes/s) filee31f0181c2 Done...
filePath2 <- tempfile()
connection2 <- file(filePath2)
writeChar("this is the content of the second file", connection, eos = NULL)
close(connection2)
file2 <- File(path = filePath2, parent = project)
file2 <- synStore(file2)
## ################################################## Uploading file to Synapse storage ##################################################
Uploading [--------------------]0.00% 0.0bytes/38.0bytes filee312bedef40
Uploading [####################]100.00% 38.0bytes/38.0bytes (66.1bytes/s) filee312bedef40 Done...
# add some annotations
synSetAnnotations(file, list(contributor = "Sage", class = "V"))
## $contributor
## $contributor[[1]]
## [1] "Sage"
##
##
## $class
## $class[[1]]
## [1] "V"
synSetAnnotations(file2, list(contributor = "UW", rank = "X"))
## $rank
## $rank[[1]]
## [1] "X"
##
##
## $contributor
## $contributor[[1]]
## [1] "UW"
Creating a View:
view <- EntityViewSchema(name = "my first file view",
columns = c(
Column(name = "contributor", columnType = "STRING"),
Column(name = "class", columnType = "STRING"),
Column(name = "rank", columnType = "STRING")),
parent = project$properties$id,
scopes = project$properties$id,
includeEntityTypes = c(EntityViewType$FILE, EntityViewType$FOLDER),
add_default_columns = TRUE)
view <- synStore(view)
We support the following entity type in a View:
EntityViewType
## $DOCKER
## EntityViewType.DOCKER
##
## $FILE
## EntityViewType.FILE
##
## $FOLDER
## EntityViewType.FOLDER
##
## $PROJECT
## EntityViewType.PROJECT
##
## $TABLE
## EntityViewType.TABLE
##
## $VIEW
## EntityViewType.VIEW
To see the content of your newly created View, use synTableQuery():
queryResults <- synTableQuery(sprintf("select * from %s", view$properties$id))
##
[####################]100.00% 1/1 Done...
Downloading [####################]100.00% 678.0bytes/678.0bytes (388.1kB/s) Job-600257325388950093261737.csv Done...
data <- as.data.frame(queryResults)
data
## ROW_ID ROW_VERSION ROW_ETAG id
## 1 9935534 1 7abd4011-f69e-4abd-bf5b-dab99b4b256e syn9935534
## 2 9935535 1 74eea69d-c814-4ccd-9e21-e0c31e684f3f syn9935535
## name createdOn createdBy
## 1 filee31f0181c2 2019-01-25 21:58:53 1
## 2 filee312bedef40 2019-01-25 21:58:55 1
## etag type currentVersion parentId
## 1 7abd4011-f69e-4abd-bf5b-dab99b4b256e file 1 syn9935533
## 2 74eea69d-c814-4ccd-9e21-e0c31e684f3f file 1 syn9935533
## benefactorId projectId modifiedOn modifiedBy dataFileHandleId
## 1 syn9935533 syn9935533 2019-01-25 21:58:56 1 459608
## 2 syn9935533 syn9935533 2019-01-25 21:58:57 1 459609
## contributor class rank
## 1 Sage V <NA>
## 2 UW <NA> X
To update ‘class’ annotation for ‘file2’, simply update the view:
The change in annotations reflect in synGetAnnotations():
A View is a Table. Please visit Tables vignettes to see how to change schema, update content, and other operations that can be done on View.