Skip to content

Conversation

MichaelChirico
Copy link
Collaborator

Part of #962

This one is somewhat of a mess... easy enough to describe what it wants to do, and it did match a bunch of our internal code. But a bit of a mess to write the linter.

Comment on lines 43 to 67
date_args_cond <- xp_or(
sprintf("not(expr[SYMBOL_FUNCTION_CALL[%s]])", xp_text_in_table(date_funs)),
"not(SYMBOL_SUB) and not(following-sibling::expr/SYMBOL_SUB)",
do.call(xp_and, as.list(vapply(date_args, arg_match_cond, character(1L))))
)

log_args_cond <- xp_or(
sprintf("not(expr[SYMBOL_FUNCTION_CALL[%s]])", xp_text_in_table(log_funs)),
"not(SYMBOL_SUB) and not(following-sibling::expr/SYMBOL_SUB)",
arg_match_cond("base")
)

c_expr_cond <- xp_and(
sprintf(
"expr[SYMBOL_FUNCTION_CALL[%s]]",
xp_text_in_table(c(no_arg_vectorized_funs, date_funs, log_funs))
),
"not(following-sibling::expr[not(expr[SYMBOL_FUNCTION_CALL])])",
sprintf(
"not(%1$s != following-sibling::expr/%1$s)",
"expr/SYMBOL_FUNCTION_CALL"
),
date_args_cond,
log_args_cond
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glue() these as well?
Very hard to read with the nested sprintf() calls.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored a little bit, hopefully a bit better.

# still preferable to vectorize the call, while being sure to use a
# consistent format for the inputs. In this case, the correct equivalent
# call is as.POSIXct(c("2021-01-01 00:00:00", "2021-01-01 01:00:00")).
# See http://google3/analysis/economics/r/izeitgeist/tests/testthat/test-izeitgeist.R;l=1058-1062;rcl=394984377.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal google link?

@MichaelChirico MichaelChirico merged commit 2d25025 into master Mar 28, 2022
@MichaelChirico MichaelChirico deleted the inner_combine branch March 28, 2022 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants