-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fixed an error when := assignment is used inside the code in qenv #233
Conversation
✅ All contributors have signed the CLA |
I have read the CLA Document and I hereby sign the CLA |
I think I'd like to write a test for this case and see what are the results. Will handle on Monday, thanks! |
Hi, @m7pr how is this one going? I am asking because we have quite a few of the scripts that could use solving the |
@kpagacz on it |
Hey, narrowing it down to a simpler case: code <- "
iris <- data.table::data.table(iris) %>%
.[, NewSpecies := factor(Species)]
"
data <- teal.data::teal_data(iris = iris, code = code)
eval_code(teal_data(), code) |
Hey @kpagacz thanks for reporting. I need team's opinion on how we test this edge case as it needs |
Ok, we changed the test to use |
I am closing this then. |
Closes #233 and alternative for #233 This removed `:=` from extracted calls so that it is not treated as `LEFT_ASSIGNMENT`. **Current main** - check row 26 ```r devtools::load_all(".") code <- " iris <- data.table::data.table(iris) %>% .[, NewSpecies := factor(Species)] " code_split <- split_code(paste(code, collapse = "\n"))[[1]] current_call <- parse(text = code_split, keep.source = TRUE) pd <- normalize_pd(utils::getParseData(current_call)) reordered_pd <- extract_calls(pd) reordered_pd[[1]] line1 col1 line2 col2 id parent token terminal text 46 2 1 3 36 46 0 expr FALSE 5 2 1 2 4 5 46 expr FALSE 4 2 6 2 7 4 46 LEFT_ASSIGN TRUE <- 45 2 9 3 36 45 46 expr FALSE 3 2 1 2 4 3 5 SYMBOL TRUE iris 17 2 9 2 36 17 45 expr FALSE 18 2 38 2 40 18 45 SPECIAL TRUE %>% 43 3 3 3 36 43 45 expr FALSE 9 2 9 2 30 9 17 expr FALSE 10 2 31 2 31 10 17 '(' TRUE ( 13 2 32 2 35 13 17 expr FALSE 12 2 36 2 36 12 17 ')' TRUE ) 6 2 9 2 18 6 9 SYMBOL_PACKAGE TRUE data.table 7 2 19 2 20 7 9 NS_GET TRUE :: 8 2 21 2 30 8 9 SYMBOL_FUNCTION_CALL TRUE data.table 11 2 32 2 35 11 13 SYMBOL TRUE iris 22 3 3 3 3 22 43 expr FALSE 21 3 4 3 4 21 43 '[' TRUE [ 23 3 5 3 5 23 43 ',' TRUE , 39 3 7 3 35 39 43 expr FALSE 38 3 36 3 36 38 43 ']' TRUE ] 20 3 3 3 3 20 22 SYMBOL TRUE . 27 3 7 3 16 27 39 expr FALSE 26 3 18 3 19 26 39 LEFT_ASSIGN TRUE := 37 3 21 3 35 37 39 expr FALSE 25 3 7 3 16 25 27 SYMBOL TRUE NewSpecies 30 3 21 3 26 30 37 expr FALSE 29 3 27 3 27 29 37 '(' TRUE ( 33 3 28 3 34 33 37 expr FALSE 32 3 35 3 35 32 37 ')' TRUE ) 28 3 21 3 26 28 30 SYMBOL_FUNCTION_CALL TRUE factor 31 3 28 3 34 31 33 SYMBOL TRUE Species ``` **Feature branch** - row removed ```r line1 col1 line2 col2 id parent token terminal text 46 2 1 3 36 46 0 expr FALSE 5 2 1 2 4 5 46 expr FALSE 4 2 6 2 7 4 46 LEFT_ASSIGN TRUE <- 45 2 9 3 36 45 46 expr FALSE 3 2 1 2 4 3 5 SYMBOL TRUE iris 17 2 9 2 36 17 45 expr FALSE 18 2 38 2 40 18 45 SPECIAL TRUE %>% 43 3 3 3 36 43 45 expr FALSE 9 2 9 2 30 9 17 expr FALSE 10 2 31 2 31 10 17 '(' TRUE ( 13 2 32 2 35 13 17 expr FALSE 12 2 36 2 36 12 17 ')' TRUE ) 6 2 9 2 18 6 9 SYMBOL_PACKAGE TRUE data.table 7 2 19 2 20 7 9 NS_GET TRUE :: 8 2 21 2 30 8 9 SYMBOL_FUNCTION_CALL TRUE data.table 11 2 32 2 35 11 13 SYMBOL TRUE iris 22 3 3 3 3 22 43 expr FALSE 21 3 4 3 4 21 43 '[' TRUE [ 23 3 5 3 5 23 43 ',' TRUE , 39 3 7 3 35 39 43 expr FALSE 38 3 36 3 36 38 43 ']' TRUE ] 20 3 3 3 3 20 22 SYMBOL TRUE . 27 3 7 3 16 27 39 expr FALSE 37 3 21 3 35 37 39 expr FALSE 25 3 7 3 16 25 27 SYMBOL TRUE NewSpecies 30 3 21 3 26 30 37 expr FALSE 29 3 27 3 27 29 37 '(' TRUE ( 33 3 28 3 34 33 37 expr FALSE 32 3 35 3 35 32 37 ')' TRUE ) 28 3 21 3 26 28 30 SYMBOL_FUNCTION_CALL TRUE factor 31 3 28 3 34 31 33 SYMBOL TRUE Species ``` This lead to the fact that below can be executed without errors ```r devtools::load_all(".") code <- " iris <- data.table::data.table(iris) %>% .[, NewSpecies := factor(Species)] " q <- eval_code(qenv(), code) cat(get_code(q)) ``` ```r iris <- data.table::data.table(iris) %>% .[, NewSpecies := factor(Species)] ``` --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: André Veríssimo <[email protected]>
Here is an example illustrating the problem:
This errors out with an informative:
And precludes launching the application.
After some investigation, I narrowed the issue to the fact that the custom
:=
is unfortunately parsed by whatever teal.code uses to parse as LEFT_ASSIGNMENT token, which causes problems in these lines:teal.code/R/utils-get_code_dependency.R
Lines 272 to 281 in 584dfc9
What happens is that
ass_cond
(great naming convention, guys) is length > 1, which means that theif
at the end errors. As a simple, dirty fix, I propose a Filter on such a custom:=
assignment operator, which cannot be used for any real assignments:This does not parse in R > 3 (and probably even more ancient), so it should be OK with the rest of the function's logic, which, I gathered, tries to establish parent-child relationships between symbols using the assignment operators.
Let me know if you want me to change something, scrap it or do something else entirely.