Skip to content

Commit 40385ba

Browse files
authored
Merge branch 'main' into fix_datatable_operators@main
2 parents 0ea4a64 + 584dfc9 commit 40385ba

File tree

10 files changed

+21
-32
lines changed

10 files changed

+21
-32
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Type: Package
22
Package: teal.code
33
Title: Code Storage and Execution Class for 'teal' Applications
4-
Version: 0.5.0.9017
5-
Date: 2024-11-14
4+
Version: 0.5.0.9018
5+
Date: 2024-11-15
66
Authors@R: c(
77
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre")),
88
person("Aleksander", "Chlebowski", , "[email protected]", role = "aut"),

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# teal.code 0.5.0.9017
1+
# teal.code 0.5.0.9018
22

33
### Enhancements
44

R/qenv-eval_code.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ setMethod("eval_code", signature = c("qenv", "character"), function(object, code
4040
return(object)
4141
}
4242
code_split <- split_code(paste(code, collapse = "\n"))
43-
4443
for (i in seq_along(code_split)) {
4544
current_code <- code_split[[i]]
4645
current_call <- parse(text = current_code, keep.source = TRUE)

R/qenv-get_code.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ setMethod("get_code", signature = "qenv", function(object, deparse = TRUE, names
141141
}
142142

143143
if (deparse) {
144-
gsub(";\n", ";", paste(gsub("\n$", "", unlist(code)), collapse = "\n"))
144+
paste(unlist(code), collapse = "\n")
145145
} else {
146146
parse(text = paste(c("{", unlist(code), "}"), collapse = "\n"), keep.source = TRUE)
147147
}

R/utils-get_code_dependency.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,15 @@ split_code <- function(code) {
484484

485485
idx_start <- c(
486486
0, # first call starts in the beginning of src
487-
char_count_lines[call_breaks[, "line"]] + call_breaks[, "col"] + 2
487+
char_count_lines[call_breaks[, "line"]] + call_breaks[, "col"] + 1
488488
)
489489
idx_end <- c(
490-
char_count_lines[call_breaks[, "line"]] + call_breaks[, "col"] + 1,
490+
char_count_lines[call_breaks[, "line"]] + call_breaks[, "col"],
491491
nchar(code) # last call end in the end of src
492492
)
493493
new_code <- substring(code, idx_start, idx_end)
494494

495-
# we need to remove leading semicolons from the calls and move them to the previous call
496-
# this is a reasult of a wrong split, which ends on the end of call and not on the ;
497-
# semicolon is treated by R parser as a separate call.
498-
gsub("^([[:space:]])*;(.+)$", "\\1\\2", new_code, perl = TRUE)
495+
# line split happens before call terminator (it could be `;` or `\n`) and the terminator goes to the next line
496+
# we need to move remove leading and add \n instead when combining calls
497+
c(new_code[1], gsub("^[\t ]*(\n|;)", "", new_code[-1]))
499498
}

tests/testthat/test-qenv_eval_code.R

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,13 @@ testthat::test_that("comments at the end of src are added to the previous call e
162162
testthat::test_that("comments from the same line are associated with it's call", {
163163
code <- c("x <- 5", " y <- 4 # comment", "z <- 5")
164164
q <- eval_code(qenv(), code)
165-
testthat::expect_identical(
166-
as.character(q@code)[2],
167-
paste0(code[2], "\n")
168-
)
165+
testthat::expect_identical(as.character(q@code)[2], code[2])
169166
})
170167

171168
testthat::test_that("alone comments at the end of the source are considered as continuation of the last call", {
172-
# todo: should be associated to the last call or be separted?
173-
code <- c("x <- 5\ny <- 10\n# comment")
169+
code <- c("x <- 5\n", "y <- 10\n# comment")
174170
q <- eval_code(eval_code(qenv(), code[1]), code[2])
175-
testthat::expect_identical(
176-
as.character(q@code)[2],
177-
"y <- 10\n# comment"
178-
)
171+
testthat::expect_identical(as.character(q@code)[2], code[2])
179172
})
180173

181174
testthat::test_that("comments passed alone to eval_code that contain @linksto tag have detected dependency", {

tests/testthat/test-qenv_extract.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ testthat::test_that("`[.` extracts the code only needed to recreate objects pass
8181
q <- eval_code(q, code)
8282
object_names <- c("x", "a")
8383
qs <- q[object_names]
84-
testthat::expect_identical(get_code(qs), c("x<-1\na<-1;"))
84+
testthat::expect_identical(get_code(qs), c("x<-1\na<-1"))
8585
})
8686

8787
testthat::test_that("`[.` comments are preserved in the code and associated with the following call", {
8888
q <- qenv()
8989
code <- c("x<-1 #comment", "a<-1;b<-2")
9090
q <- eval_code(q, code)
9191
qs <- q[c("x", "a")]
92-
testthat::expect_identical(get_code(qs), c("x<-1 #comment\na<-1;"))
92+
testthat::expect_identical(get_code(qs), c("x<-1 #comment\na<-1"))
9393
})

tests/testthat/test-qenv_get_code.R

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ testthat::test_that("get_code called with qenv.error returns error with trace in
4747
)
4848
})
4949

50-
testthat::test_that("get_code returns code with comments and empty spaces", {
50+
testthat::test_that("get_code formatted returns code asis but replaces `;` with `\n`", {
5151
code <- "
5252
# header comment after white space
5353
@@ -58,7 +58,7 @@ testthat::test_that("get_code returns code with comments and empty spaces", {
5858
# closing comment
5959
"
6060
q <- eval_code(qenv(), code)
61-
testthat::expect_equal(get_code(q), code)
61+
testthat::expect_equal(get_code(q), gsub(";", "\n", code))
6262
})
6363

6464
# names parameter -------------------------------------------------------------------------------------------------
@@ -240,14 +240,12 @@ testthat::describe("get_code for specific names", {
240240
testthat::expect_length(get_code(q1, deparse = FALSE), 1)
241241
})
242242

243-
testthat::it("does not break if code is separated by ;", {
244-
code <- c(
245-
"a <- 1;a <- a + 1"
246-
)
243+
testthat::it("detects calls associated with object if calls are separated by ;", {
244+
code <- c("a <- 1;b <- 2;a <- a + 1")
247245
q <- eval_code(qenv(), code)
248246
testthat::expect_identical(
249247
get_code(q, names = "a"),
250-
code
248+
"a <- 1\na <- a + 1"
251249
)
252250
})
253251

tests/testthat/test-qenv_get_messages.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ testthat::test_that("get_messages accepts a qenv object with a single eval_code
4949
"~~~ Messages ~~~\n",
5050
"> This is a message 1!",
5151
"when running code:",
52-
"message(\"This is a message 1!\")\n\n",
52+
"message(\"This is a message 1!\")\n",
5353
"> This is a message 2!",
5454
"when running code:",
5555
"message(\"This is a message 2!\")\n",

tests/testthat/test-qenv_get_warnings.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ testthat::test_that("get_warnings accepts a qenv object with a single eval_code
4949
"~~~ Warnings ~~~\n",
5050
"> This is a warning 1!",
5151
"when running code:",
52-
"warning(\"This is a warning 1!\")\n\n",
52+
"warning(\"This is a warning 1!\")\n",
5353
"> This is a warning 2!",
5454
"when running code:",
5555
"warning(\"This is a warning 2!\")\n",

0 commit comments

Comments
 (0)