Skip to content
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

Allow dollar operator to have a square brackets operator as left-hand parameter. #37

Open
lloyddewit opened this issue Nov 26, 2023 · 3 comments

Comments

@lloyddewit
Copy link
Owner

See IDEMSInternational/R-Instat#8663 .

The line that causes the problem can be simplified to a[b]$c.

In theory, this code is not legal R. This is because the $ operator has a higher precedence than the [ operator (see extract from R documentation below). Therefore RScript evaluates the $ operator first, finds that there is no valid operand on the left-hand side and raises an error. According to the R documentation I think this is correct.

However, I ran RStudio does accept this!

Should we change RScript to be consistent with RStudio or should we be purist and follow the official R documentation?

image

@rdstern
Copy link

rdstern commented Nov 26, 2023

@lloyddewit that's really interesting. I think you said, in #8663 that the offending a[b]$c could be "corrected" to a([b])$c?
So, we could remain purist, as regards to RScript and not allow a[b]$c, because it is nice to fit within the official rules. My main problem, when finished if there is code that runs in RStudio and we can't easily make it run in R-Instat. If we remain pure, we can mention this point in our documentation.

So, I really would like us to be able to run - as far as we know - scripts that run in RStudio. But RScript seems to be well defined and perhaps that should take precedence. Once we start tweaking, we don't know where to stop?

So happy for either approach, with a slight preference for RScript, rather than RStudio? I wonder what your view is?

@lloyddewit
Copy link
Owner Author

a[b]$c could be "corrected" to a([b])$c?

@rdstern nearly correct, the bracket operator has 2 operands (a and b) so the brackets have to placed as follows: (a[b])$c, hope that makes sense.

I agree with the rest of your comment. I suggest we leave this issue open for now. If this is a rare case, then I hope that the workaround is OK. If you hit more scripts that use a[b]$c, then we could consider implementing.

thanks

@rdstern
Copy link

rdstern commented Nov 26, 2023

@lloyddewit as you say. If lots of code breaks the rule, then we follow RStudio. Otherwise we have the RScript "solution". In addition we keep looking for different examples - if any - where RStudio allows code that should not be permitted under the RScript rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants