-
-
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
get_code
to return concatenated code string and removed format_expression
#176
Conversation
get_code
to return concatenated code sting.get_code
to return concatenated code string and removed format_expression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have one comment regarding the changes for this issue. Other than that, I think everything looks fine to me. It's good that this issue is not a breaking change, so I believe updating just the NEWS.md
is sufficient.
Could you please change the target branch to main
instead of refactor
in this and all the related child PRs? I think this issue is independent of the refactor
changes, and we can merge it before or after the refactor
without any issues.
replace_code(object, code = paste(lang2calls(code), collapse = "\n")) | ||
}) | ||
|
||
#' @keywords internal | ||
setMethod("replace_code", signature = c("qenv", "expression"), function(object, code) { | ||
replace_code(object, code = format_expression(code)) | ||
replace_code(object, code = paste(lang2calls(code), collapse = "\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having second thoughts about removing format_expression
. It's used in multiple places. I think it can stay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a similar thought previously, but following a conversation with @chlebowa it was clarified that the function simply uses paste with a designated collapse parameter after processing with lang2calls
. The format_expression
function originally had a more complex design but it was simplified into a simple one-liner in a past refactoring phase. Currently, it's essentially redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. We don't want to have too simple wrappers. Check out the use of lapply(x, [[, y)
throughout teal.slice
. That used to be a function but we decided to use base calls.
On top of that, soon we will be down to just a few uses of format_expression
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format_expression sounds like a wrapper for paste, where you overwrite default collapse param :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you guys consider having lang2calls
return the paste(...)
?
It seems that it is only used this way in the package (other than in tests)
ps. and rename it to lang2str
or lang2character
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is recursion in lang2calls
and implementing the paste function with collapse directly inside lang2calls
can lead to unintended results due to concatenation of results from each recursive call.
Co-authored-by: Vedha Viyash <49812166+vedhav@users.noreply.github.com> Signed-off-by: kartikeya kirar <kirar.kartikeya1@gmail.com>
We also have |
@kartikeyakirar why it only shortens the length for |
For deparse= Here expression is of length 3
even if you collpase it before converting it into expression result is same
|
@kartikeyakirar yeah, because you need to paste > code <- c('a<-1', 'b<-2', 'c<-2')
> length(parse(text = code))
[1] 3
> length(parse(text = paste(code, collapse = '\n')))
[1] 3
> length(parse(text = paste(c('{', code, '}'), collapse = '\n')))
[1] 1 |
yes. It won't alter the interpretation of the code when it's later evaluated. Why didn't I think of this! I will update test and make change in teal as well. thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any other comments, Good job in reflecting the change in all repos. LGTM
…ression` (#206) part of insightsengineering/teal.code#176 --------- Signed-off-by: kartikeya kirar <kirar.kartikeya1@gmail.com> Co-authored-by: Vedha Viyash <49812166+vedhav@users.noreply.github.com> Co-authored-by: vedhav <vedhaviyash4@gmail.com>
this fixes #173
In this pull request, I've made updates to both the
get_code
andreplace_code
methods. Now, when thedeparse
arg is set to TRUE, these methods will return a concatenated string. Specifically, theget_code
method will return character(0) when used withnew_qenv(),
provided no code has been set. As forreplace_code,
it will first split the input string using "\n", then replace the last string in this sequence. Finally, it concatenates these strings again before replacing the code.Removed
format_expression
function.Example
Also review following modules for PR for changes.
get_code
to return concatenated code string teal#976get_code
to return concatenated code string and removedformat_expression
teal.data#206get_code
to return concatenated code string teal.modules.general#615get_code
to return concatenated code string teal.modules.clinical#898get_code
to return concatenated code string teal.goshawk#250get_code
to return concatenated code string teal.osprey#244