@@ -51,12 +51,21 @@ saveDictionary <- function(name, dictionary) {
5151 # -------------------------------
5252 # 1️⃣ Save CRAN/GitHub-compliant copy (/data/)
5353 # -------------------------------
54- data_path <- file.path(system.file(package = " alspac" ), " data" )
55- if (! dir.exists(data_path )) dir.create(data_path , recursive = TRUE )
54+ data_path <- system.file(" data" , package = " alspac" )
5655
57- save(list = name ,
58- file = file.path(data_path , paste0(name , " .rdata" )),
59- envir = globals )
56+ if (nzchar(data_path )) {
57+ # Installed package case
58+ save(list = name ,
59+ file = file.path(data_path , paste0(name , " .rda" )),
60+ envir = globals )
61+ } else {
62+ # Dev case (write into source tree)
63+ data_path <- file.path(getwd(), " data" )
64+ if (! dir.exists(data_path )) dir.create(data_path , recursive = TRUE )
65+ save(list = name ,
66+ file = file.path(data_path , paste0(name , " .rda" )),
67+ envir = globals )
68+ }
6069
6170 # -------------------------------
6271 # 2️⃣ Save dev copy (/inst/data/) for load_all() testing
@@ -141,7 +150,7 @@ createDictionary <- function(datadir="Current", name= "current", quick=FALSE, so
141150 alspacdir <- options()$ alspac_data_dir
142151 datadir <- file.path(alspacdir , datadir )
143152
144- # --- NEW list.files section with version handling ---
153+ # ---list.files section with version handling ---
145154 files <- list.files(datadir ,
146155 pattern = " dta$" ,
147156 full.names = TRUE ,
@@ -156,7 +165,7 @@ createDictionary <- function(datadir="Current", name= "current", quick=FALSE, so
156165 num <- suppressWarnings(as.integer(sub(" ([0-9]+).*" , " \\ 1" , vers )))
157166 let <- sub(" [0-9]+" , " " , vers )
158167
159- # Build table of file info
168+ # Build table of file info
160169 file_info <- data.frame (
161170 file = files ,
162171 base = base ,
@@ -170,7 +179,7 @@ createDictionary <- function(datadir="Current", name= "current", quick=FALSE, so
170179 dplyr :: arrange(dplyr :: desc(num ), dplyr :: desc(let )) | >
171180 dplyr :: slice_head(n = 1 ) | >
172181 dplyr :: pull(file )
173- # --- END of new section ---
182+ # --- END of new section ---
174183
175184 dictionary <- parallel :: mclapply(latest_files , function (file ) {
176185 cat(date(), " loading" , file , " \n " )
@@ -195,7 +204,7 @@ createDictionary <- function(datadir="Current", name= "current", quick=FALSE, so
195204 # # Assign in globals so retrieveDictionary() can find it
196205 assign(name , dictionary , globals )
197206
198- # # Save using your robust saveDictionary() function
207+ # # Save using saveDictionary() function
199208 saveDictionary(name , dictionary )
200209
201210 invisible (dictionary )
0 commit comments