-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
data/
directory automatically accessible to exercises (#539)
Co-authored-by: Garrick Aden-Buie <garrick@adenbuie.com> Co-authored-by: Barret Schloerke <barret@rstudio.com>
- Loading branch information
1 parent
a24555f
commit 14d679a
Showing
16 changed files
with
583 additions
and
523 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
copy_data_dir <- function(source_dir, exercise_dir) { | ||
if (is.null(source_dir)) { | ||
# First check options(), then environment variable, then default to "data/" | ||
source_dir <- getOption( | ||
"tutorial.data_dir", | ||
Sys.getenv("TUTORIAL_DATA_DIR", if (dir.exists("data")) "data" else "") | ||
) | ||
} | ||
|
||
if (identical(source_dir, "")) { | ||
return(invisible(NULL)) | ||
} | ||
|
||
if (!dir.exists(source_dir)) { | ||
rlang::abort( | ||
"An error occurred with the tutorial: the data directory does not exist.", | ||
class = "learnr_missing_source_data_dir" | ||
) | ||
} | ||
|
||
dest_dir <- file.path(exercise_dir, "data") | ||
dir.create(dest_dir) | ||
|
||
if (!dir.exists(dest_dir)) { | ||
rlang::abort( | ||
"An error occurred with the tutorial: we weren't able to create the data directory for this exercise.", | ||
class = "learnr_missing_dest_data_dir" | ||
) | ||
} | ||
|
||
file.copy(dir(source_dir, full.names = TRUE), dest_dir, recursive = TRUE) | ||
|
||
return(invisible(dest_dir)) | ||
} |
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
Oops, something went wrong.