Skip to content

Commit

Permalink
added script to download file via R #2438
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Sep 4, 2015
1 parent 5e5dcf5 commit 812424a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/issues/2438/download.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
arg <- commandArgs(trailingOnly = TRUE)

download.dataverse.file <- function(url) {
if (length(url) == 0L) {
return(
"Please provide a URL to a file: http://guides.dataverse.org/en/latest/api/dataaccess.html"
)
}
# Examples of URLs for tsv, original, RData, JSON, DDI/XML:
# https://groups.google.com/d/msg/dataverse-community/fFrJi7NnBus/LNpfXItbtZYJ
#
# This script assume the tsv URL is used. File id 91 is just an example. You must
# look up the id of the file. As of this writing the easiest way is via SWORD:
# https://github.com/IQSS/dataverse/issues/1837#issuecomment-121736332
#
# url.to.download = 'https://apitest.dataverse.org/api/v1/access/datafile/91'
url.to.download = url
tsvfile = 'file.tsv'
download.file(url = url.to.download, destfile =
tsvfile, method = 'curl')
mydata <- read.table(tsvfile, header = TRUE, sep = "\t")
print(mydata)
unlink(tsvfile)
}

download.dataverse.file(arg)

1 comment on commit 812424a

@pdurbin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.