Skip to content

Instantly share code, notes, and snippets.

@cbare
Created January 29, 2013 22:25
Show Gist options
  • Select an option

  • Save cbare/4668549 to your computer and use it in GitHub Desktop.

Select an option

Save cbare/4668549 to your computer and use it in GitHub Desktop.
The R client for Sage Synapse works transparently with R data files. Using other types of files requires a bit more work. Here's a short demonstration of how to do it.
## Loading with files in the R synapse client
##################################################
## If you haven't already, install the synapse R client
# source('http://depot.sagebase.org/CRAN.R')
# pkgInstall(c("synapseClient"))
library(synapseClient)
## list the files in a project
synapseQuery('select id,name from entity where parentId=="syn1661878"')
# entity.name entity.id
# 1 data.txt syn1661879
# 2 generate_random_data.py syn1661881
# 3 square.py syn1661884
# 4 squares.txt syn1661886
## let's get data.txt, which happens to be a text file holding a bunch
## of floating point numbers
e <- loadEntity('syn1661879')
## list the files
e@objOwn$objects@fileCache$files()
# [1] "data.txt"
## paste together the filename(s)
filename <- paste(e@objOwn$objects@fileCache$getCacheDir(), e@objOwn$objects@fileCache$files(), sep="/" )
## read the data with the method appropriate to the file type,
## in this case a simple scan will do. Otherwise, try read.delim
## or read.csv.
data <- scan(file=filename)
@cbare
Copy link
Copy Markdown
Author

cbare commented Feb 6, 2013

Loading the data is format specific. The call to scan might be replaced by read.table, read.csv or something else, depending on the type of data in the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment