Skip to content

Commit

Permalink
remove temp files afterwards
Browse files Browse the repository at this point in the history
  • Loading branch information
wibeasley committed Jan 1, 2021
1 parent 2a1e355 commit 4e80180
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Tests use https://demo.dataverse.org/dataverse/dataverse-client-r/. (#40)
* Fixes most get_file errors by removing query argument (#33 @kuriwaki)
* Fix getting multiple files by id in `get_file()` (#47 @adam3smith)
* Temporary files created by `get_file()` are automatically deleted.

# CHANGES TO dataverse 0.2.1

Expand Down
16 changes: 10 additions & 6 deletions R/get_dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ get_dataframe_by_doi <- function(filedoi,
#'
#' @keywords internal
get_dataframe_internal <- function(raw, filename, .f) {
tmp <- tempfile(filename)
writeBin(raw, tmp)

do.call(.f, list(tmp))

# TODO: unlink/delete tmp file in a try/catch/finally block.
tryCatch(
{
tmp <- tempfile(filename)
writeBin(raw, tmp)
do.call(.f, list(tmp))
},
finally = {
if (file.exists(tmp)) unlink(tmp)
}
)
}

0 comments on commit 4e80180

Please sign in to comment.