-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added script to download file via R #2438
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
812424a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #2700 and https://groups.google.com/d/msg/dataverse-community/fFrJi7NnBus/19_PcL50CgAJ for more context on this script.