Skip to content

Commit a619bc4

Browse files
committed
Update storage handling
1 parent 82d77d6 commit a619bc4

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

R/setup.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
setup_offline_storage <- function(dir = "/opt/data", persist_data = FALSE) {
2+
# Copy the storage.yml from inst/config to the working directory
3+
if (!file.exists("storage.yml")) {
4+
file.copy("inst/config/storage.yml", "storage.yml", overwrite = TRUE)
5+
}
6+
# Edit the storage.yml file to set the directory and change
7+
storage_config <- readLines("storage.yml")
8+
storage_config <- gsub("directory: .*", paste0("directory: ", dir), storage_config)
9+
writeLines(storage_config, "storage.yml")
10+
message("storage.yml created with directory: ", dir, ". Local files can now be read from this directory.")
11+
# If persist_data is TRUE, set up the offline storage directory
12+
if (persist_data) {
13+
storage_config <- readLines("storage.yml")
14+
storage_config <- gsub("persist_data: .*", "persist_data: true", storage_config)
15+
writeLines(storage_config, "storage.yml")
16+
# make sure the directory exists
17+
if (!dir.exists(dir)) {
18+
dir.create(dir, recursive = TRUE)
19+
message("Directory created: ", dir)
20+
}
21+
message("storage.yml created with persist_data: true. Downloaded files will now be written to this directory and persist indefinitely.")
22+
} else {
23+
message("storage.yml created with persist_data: false. Downloaded files will not persist after the session ends.")
24+
}
25+
message("Offline storage setup complete.")
26+
}

R/stageData.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ getStaged <- function(rec, storageConfig = readStorageConfig()) {
135135
#'
136136

137137
readStorageConfig <- function() {
138-
yaml::read_yaml(system.file('config/storage.yml', package = 'gaiaCore'))
138+
yaml::read_yaml('./storage.yml')
139139
}
140140

141141

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,18 @@ connectionDetails <- DatabaseConnector::createConnectionDetails(
2727

2828
# Support
2929
- Please use the <a href="https://github.com/OHDSI/gaiaCore/issues?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen">GitHub issue tracker</a> for all bugs, issues, and feature requests
30+
31+
# Details
32+
## Offline Storage
33+
34+
Offline storage can be set up for the purpose of loading local datasets in gaiaDB and persisting downloaded source datasets.
35+
36+
Offline storage is configured using a file `storage.yml` to specify a directory and whether or not to persist downloaded datasets.
37+
38+
You can create this file using the helper function `setup_offline_storage()`:
39+
40+
```R
41+
setup_offline_storage(dir = "/path/to/data", persist_data = TRUE)
42+
```
43+
44+
The above command will create a file named `storage.yml` in your working directory. It will also create a directory `path/to/data` if one does not already exist. Any datasets downloaded using `loadGeometry()` or `loadVariable()` will be saved to this directory!

inst/config/storage.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
offline_storage:
2+
directory: /opt/data
3+
persist_data: false

0 commit comments

Comments
 (0)