Skip to content

Commit a240814

Browse files
committed
Fix save function
Replace save in create function
1 parent 86562e2 commit a240814

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

.Rprofile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Automatically load the "current" dictionary from /data on load (FOR DEVELOPMENT ONLY)
2+
#This file is for development only and should not be committed to github
3+
4+
#if (file.exists("data/current.rdata")){
5+
# try({
6+
# load("data/current.rdata", envir = .GlobalEnv)
7+
# message("Loaded 'current' from data/current.rdata")
8+
# }, silent = TRUE)
9+
#}

R/dictionary.r

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,28 @@ retrieveDictionary <- function(name) {
4545
}
4646

4747
saveDictionary <- function(name, dictionary) {
48-
assign(name, dictionary, globals)
49-
#if (name == "current" || name == "useful")
50-
# combineDictionaries()
51-
52-
path <- file.path(system.file(package="alspac"), "data")
53-
if (!file.exists(path)) {
54-
dir.create(path)
55-
}
56-
save(list=name,
57-
file=file.path(path, paste(name, "rdata", sep=".")),
58-
envir=globals)
48+
# Save in the globals environment
49+
assign(name, dictionary, globals)
50+
51+
# -------------------------------
52+
# 1️⃣ Save CRAN/GitHub-compliant copy (/data/)
53+
# -------------------------------
54+
data_path <- file.path(system.file(package = "alspac"), "data")
55+
if (!dir.exists(data_path)) dir.create(data_path, recursive = TRUE)
56+
57+
save(list = name,
58+
file = file.path(data_path, paste0(name, ".rdata")),
59+
envir = globals)
60+
61+
# -------------------------------
62+
# 2️⃣ Save dev copy (/inst/data/) for load_all() testing
63+
# -------------------------------
64+
inst_path <- file.path(getwd(), "inst", "data") # relative to project root
65+
if (!dir.exists(inst_path)) dir.create(inst_path, recursive = TRUE)
66+
67+
save(list = name,
68+
file = file.path(inst_path, paste0(name, ".rdata")),
69+
envir = globals)
5970
}
6071

6172
#' Checks a dictionary
@@ -176,11 +187,16 @@ createDictionary <- function(datadir="Current", name= "current", quick=FALSE, so
176187

177188

178189
dictionary <- dictionary[which(dictionary$counts > 0),]
179-
## add sources info
190+
191+
192+
## Add sources info
180193
dictionary <- addSourcesToDictionary(dictionary, sourcesFile)
181194

182-
## Save to /data/ as proper package dataset
183-
do.call(usethis::use_data, list(as.name(name), overwrite = TRUE))
195+
## Assign in globals so retrieveDictionary() can find it
196+
assign(name, dictionary, globals)
197+
198+
## Save using your robust saveDictionary() function
199+
saveDictionary(name, dictionary)
184200

185201
invisible(dictionary)
186202
}

0 commit comments

Comments
 (0)