@@ -45,17 +45,28 @@ retrieveDictionary <- function(name) {
4545}
4646
4747saveDictionary <- 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