nrow_subset_linter | R Documentation |
nrow(subset(x, .))
Using nrow(subset(x, condition))
to count the instances where condition
applies inefficiently requires doing a full subset of x
just to
count the number of rows in the resulting subset.
There are a number of equivalent expressions that don't require the full
subset, e.g. with(x, sum(condition))
(or, more generically,
with(x, sum(condition, na.rm = TRUE))
).
nrow_subset_linter()
best_practices, consistency, efficiency
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "nrow(subset(x, is_treatment))",
linters = nrow_subset_linter()
)
lint(
text = "nrow(filter(x, is_treatment))",
linters = nrow_subset_linter()
)
lint(
text = "x %>% filter(x, is_treatment) %>% nrow()",
linters = nrow_subset_linter()
)
# okay
lint(
text = "with(x, sum(is_treatment, na.rm = TRUE))",
linters = nrow_subset_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.