Skip to content

Commit a09814a

Browse files
Bug/isolated object name replacement (#113)
* collate isolated objects using list name set method * update tests * correct test to trigger bug in previous implementation
1 parent 02902c6 commit a09814a

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

R/build.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ callr_render <- function(files_to_process, render_args, render_mode, r_session_w
117117

118118
if (render_mode == "isolate"){
119119
# Earlier object(s) with same name are overwritten here
120-
objs <- utils::modifyList(objs, get_callr_globals(rs), keep.null = TRUE)
120+
objs[names(get_callr_globals(rs))] <- get_callr_globals(rs)
121121
if ( file_to_process != files_to_process[ length(files_to_process) ] ){
122122
rs$close()
123123
rs <- callr::r_session$new(wait=TRUE, wait_timeout=r_session_wait_timeout)

tests/testthat/setup.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ createPkg <- function(temp_dir, package_name, more_args = list()){
7474
c(
7575
"library(DPR2)",
7676
"mymatrix <- matrix(1:16, nrow=4)",
77+
"mydataframe <- data.frame(x=1:3, y=LETTERS[1:3])",
7778
"dpr_save('mymatrix')"
7879
),
7980
file.path(path, "processing/02.R")

tests/testthat/test-build.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ testthat::test_that("checking package build", {
4141
)
4242
dpr_yaml_set(path, r_session_wait_timeout = 3000)
4343

44-
dpr_build(path, process_on_build = "02.R")
44+
## test tabular objects made in isolate can be overwritten, count vignettes, check data save
45+
dpr_build(path, process_on_build = c("01.R", "02.R"))
4546
vign <- list.files(file.path(path, "vignettes"))
4647
expect_true(length(vign) == 2)
4748
datn <- list.files(file.path(path, "data"))
48-
expect_true(datn == "mymatrix.rda")
49+
expect_true(all(datn == c("mydataframe.rda", "mymatrix.rda", "myyaml.rda")))
4950

5051
dpr_build(path, process_on_build = "A1.R", build_tarball = TRUE)
5152
vign <- list.files(file.path(path, "vignettes"))

0 commit comments

Comments
 (0)