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

Write an XPath for extended known-literal expressions #963

Open
MichaelChirico opened this issue Mar 20, 2022 · 1 comment
Open

Write an XPath for extended known-literal expressions #963

MichaelChirico opened this issue Mar 20, 2022 · 1 comment
Labels
feature a feature request or enhancement

Comments

@MichaelChirico
Copy link
Collaborator

Follow-up to #957 (comment)

There are a few places that would benefit from some shared logic about what constitutes a "literal expression" along the lines of these:

const_exprs <- c(
  '"a"',
  '1',
  '1+1i',
  'c("a")',
  'c("a", 1)',
  'c("a", 1+1i)',
  'rep("a", 2)',
  'rep("a", n)',
  'rep(c("a", "b"), 5)',
  'c(rep("a", 10), rep("b", 10))'
)

but excluding non-constant expressions like:

non_constant_exprs <- c(
  'a',
  'a + 1',
  'foo(1)',
  'foo(c(1, 2))'
)

I think c() and rep() are the most common ways to build constant expressions, so we can limit it to combinations of those. Note that I consider rep(1:3, n) as being "constant" here, as the variable part is "constant enough" for the places where we'd use this:

  • strings_as_factors_linter which looks for data.frames declared with known-character columns
  • expect_{type,length,named,s3_class}_linter which look for literal exprs in the 1st argument
  • yoda_test_linter which does the same
@AshesITR
Copy link
Collaborator

I'm not sure whether it's good to call the rep(1:3, n) expression a constant (but willing to call it "almost constant").
Regarding functions used: 1:3 == seq_len(3) is what I default to due to 1:n being bad for n == 0.
This means we could whitelist seq, seq_len, seq_along and seq.int as well.

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

No branches or pull requests

2 participants