-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from grattan/private-data-location
add ability to look for microdata in other locations
- Loading branch information
Showing
14 changed files
with
161 additions
and
21 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
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
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
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,36 @@ | ||
#' Add a specified location for microdata not in the Grattan data warehouse | ||
#' @param path File path to non-data warehouse microdata location, such as | ||
#' `file.path("~", "my_data", "hilda") | ||
#' | ||
#' @description Some microdata, such as HILDA, has access restrictions that | ||
#' mean it cannot be stored on Dropbox, even with the security controls we | ||
#' have in place. This function allows you to store microdata somewhere else, | ||
#' but still load it with the `read_microdata()` function. This increases | ||
#' reproducibility within Grattan. `read_microdata()` will look both in the | ||
#' data warehouse and in the location you add with `add_microdata_location()`. | ||
#' @return Sets an environment variable `"R_GRATTANDATA_LOCATION"`. When | ||
#' this variable is set, `grattandata` functions including `read_microdata()` | ||
#' will look for the data file(s) you request in the specified location as well | ||
#' as in the Grattan data warehouse. | ||
#' | ||
#' @note You can only set one location (in addition to the Grattan data | ||
#' warehouse). All subfolders of the defined location will be included in | ||
#' the search path for `read_microdata()`. | ||
#' | ||
#' We recommend that you use the `add_microdata_location()` function in your | ||
#' scripts rather than defining the `"R_GRATTANDATA_LOCATION"` environment | ||
#' variable elsewhere, to improve clarity/reproducibility of your code. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' add_microdata_location(path = file.path("documents", "hilda")) | ||
#' | ||
#' read_microdata("hilda_file.dta") | ||
#' } | ||
|
||
add_microdata_location <- function(path) { | ||
Sys.setenv("R_GRATTANDATA_LOCATION" = path) | ||
|
||
invisible(TRUE) | ||
} |
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,19 @@ | ||
test_that("read_microdata() can load non-warehouse data from path defined with add_microdata_location()", { | ||
skip_on_cran() | ||
skip_on_ci() | ||
|
||
temp_data <- tempfile(fileext = ".csv") | ||
on.exit(unlink(temp_data)) | ||
|
||
temp_dir <- dirname(temp_data) | ||
fake_data <- data.frame(x = sample(0:9, size = 1000, replace = TRUE)) | ||
write.csv(fake_data, temp_data, row.names = FALSE) | ||
|
||
manually_loaded_data <- rio::import(temp_data, setclass = "tbl_df") | ||
|
||
add_microdata_location(path = temp_dir) | ||
|
||
loaded_with_package <- read_microdata(basename(temp_data)) | ||
|
||
expect_equal(manually_loaded_data, loaded_with_package) | ||
}) |
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
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
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