You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Functions with side effects are not detected as dependencies #278
The code on apps will omit the second and third lines. But when user copies and pastes the code result will be different as it will use a different seed and the check step ( stopifnot(rlang::hash(ADSL) == "...) will fail.
srv_source_code() doesn't return those lines because on teal app because on the reactive module_teal_data of the module() function any code that is not a dependency of the data required is dropped (L468 of module_nested_tabs.R).
sessionInfo()
Relevant log output
Code of Conduct
I agree to follow this project's Code of Conduct.
Contribution Guidelines
I agree to follow this project's Contribution Guidelines.
The lack of dependencies is noted on ?teal.code::get_code() instead of teal_data or qenv:
Lines where side effects occur can be flagged by adding "# @linksto <object name>" at the end.
This issue can be closed but I suggest to add a warning if there is some common functions without the linksto comment, as this will help users be more aware of this: set.seed() and options() are the ones that come to my mind.
After analyzing together with @averissimo , I understand better what is happening. I do not see an easy solution, but the current scenario can be improved.
The problem of within is that it evaluates R expression, and R expressions only capture the structure of the code, not other details like the code style (spaces, tabs) or code comments. "@linksto" is a code comment, therefore it will always be ignored in within.
e <- expression({
test <- runif(1) # code comment
})
print(e)
On the other hand, function eval_code uses string as input, which can be parsed. In eval_code we can include more information, like code comments. That is why @linksto works.
What can be done?
Improve documentation so users and teal developers are more aware of the limitations of eval_code and within to carefully choose one or another. That would mean:
Add more documentation and even examples to both functions to make this information clearly available
Set a check in within that will trigger a warning when code comments are used, or when at least when teal tags like "# @linksto" are used
Additionally, we could add a warning in within expressions that would be trigger if set.seed or options are called
If required, we can also include examples and explanation in tutorials.
This alternative is quick and will reduce the chance of error.
Add operator to within to link dependent code expressions
something like %linksto% that in a expression like
qenv() |>
within({
set.seed(2) %linktsto% a
a <- runif(1)
})
Would capture the code dependency of a with linksto
This would require more developing time. We also need to see if it is required or we are good using within for code expressions and eval_code for code strings.
I think that the improvement in documentation is better.
We have replaced on code and examples to within, pointing this now might cause some problems.
We might still get the comment with utils::getParseData if we set option(keep.source = TRUE) inside within.
However, I agree that more documentation around this feature/corner case would be helpful. It is only mentioned in a line.
BTW if we improve documentation we should add the within alias for this method. This way users will find it with ?within.
Hi @osenan and @llrs-roche , so sorry I was off and gogonzo was off. If we were there we would immediately tell you that side-effects can only be dealt with # @linksto and eval_code. eval_code deals with character code, where within doesn't and looses comments.
Looks like you already learnt that, the hard way. At least now you know, which is good.
I give you my blessing to improve the documentation whenever you want : ) if only it makes the user experience better.
Lastly, you can see that library() calls are detected, even though they don't have # @linksto tags. Maybe you can have a look on how this is done for detection of library() and do the same for options and set.seed. However, even though set.seed is often needed for some objects, it is not always needed for all objects, so I would not make this function to be defaulty extracted.
Activity
llrs-roche commentedon Nov 3, 2025
The lack of dependencies is noted on
?teal.code::get_code()instead ofteal_dataorqenv:This issue can be closed but I suggest to add a warning if there is some common functions without the
linkstocomment, as this will help users be more aware of this:set.seed()andoptions()are the ones that come to my mind.llrs-roche commentedon Nov 26, 2025
This is not solved with linksto when the code of a variable is required:
Created on 2025-11-26 with reprex v2.1.1
Note how the exported code for ADSL doesn't have the
set.seed()callosenan commentedon Dec 4, 2025
Hi @llrs-roche the problem is in the
withinfunction.If you look at this code it works:
I have to fix therefore the way
withinis implementedosenan commentedon Dec 5, 2025
After analyzing together with @averissimo , I understand better what is happening. I do not see an easy solution, but the current scenario can be improved.
The problem of
withinis that it evaluates R expression, and R expressions only capture the structure of the code, not other details like the code style (spaces, tabs) or code comments. "@linksto" is a code comment, therefore it will always be ignored in within.On the other hand, function
eval_codeuses string as input, which can be parsed. Ineval_codewe can include more information, like code comments. That is why @linksto works.What can be done?
eval_codeandwithinto carefully choose one or another. That would mean:withinexpressions that would be trigger ifset.seedor options are calledIf required, we can also include examples and explanation in tutorials.
This alternative is quick and will reduce the chance of error.
something like %linksto% that in a expression like
Would capture the code dependency of a with linksto
This would require more developing time. We also need to see if it is required or we are good using
withinfor code expressions andeval_codefor code strings.I think that the improvement in documentation is better.
llrs-roche commentedon Dec 5, 2025
We have replaced on code and examples to
within, pointing this now might cause some problems.We might still get the comment with
utils::getParseDataif we setoption(keep.source = TRUE)inside within.However, I agree that more documentation around this feature/corner case would be helpful. It is only mentioned in a line.
BTW if we improve documentation we should add the
withinalias for this method. This way users will find it with?within.m7pr commentedon Dec 8, 2025
Hi @osenan and @llrs-roche , so sorry I was off and gogonzo was off. If we were there we would immediately tell you that side-effects can only be dealt with
# @linkstoandeval_code.eval_codedeals with character code, wherewithindoesn't and looses comments.Looks like you already learnt that, the hard way. At least now you know, which is good.
I give you my blessing to improve the documentation whenever you want : ) if only it makes the user experience better.
Lastly, you can see that
library()calls are detected, even though they don't have# @linkstotags. Maybe you can have a look on how this is done for detection oflibrary()and do the same foroptionsandset.seed. However, even thoughset.seedis often needed for some objects, it is not always needed for all objects, so I would not make this function to be defaulty extracted.Expand documentation for the use and reproducibility of side effects …