Repository navigation
Description
Is this the expected behaviour (with styler::tidyverse_style(scope = "indention"))?
txt <- '
m2 <- gam(list(max_temp ~ s(month, bs = "cc", k = 12) + s(year) +
ti(month, year, bs = c("cc", "cr"), k = c(12, 10)),
~ s(month, bs = "cc", k = 12),
~ s(month, bs = "cc", k = 12) + s(year)),
method = "REML",
data = month_maxima,
family = gevlss(link = list("identity", "identity", "logit")),
knots = knots,
control = ctrl,
optimizer = "efs")'
style_text(txt, scope = "indention", indent_by = 2)output:
m2 <- gam(list(max_temp ~ s(month, bs = "cc", k = 12) + s(year) +
ti(month, year, bs = c("cc", "cr"), k = c(12, 10)),
~ s(month, bs = "cc", k = 12),
~ s(month, bs = "cc", k = 12) + s(year)),
method = "REML",
data = month_maxima,
family = gevlss(link = list("identity", "identity", "logit")),
knots = knots,
control = ctrl,
optimizer = "efs")
I would have expected something like
m2 <- gam(list(max_temp ~ s(month, bs = "cc", k = 12) + s(year) +
ti(month, year, bs = c("cc", "cr"), k = c(12, 10)),
~ s(month, bs = "cc", k = 12),
~ s(month, bs = "cc", k = 12) + s(year)),
method = "REML",
data = month_maxima,
family = gevlss(link = list("identity", "identity", "logit")),
knots = knots,
control = ctrl,
optimizer = "efs")
or (perhaps preferably - ideally?)
m2 <- gam(list(max_temp ~ s(month, bs = "cc", k = 12) + s(year) +
ti(month, year, bs = c("cc", "cr"), k = c(12, 10)),
~ s(month, bs = "cc", k = 12),
~ s(month, bs = "cc", k = 12) + s(year)),
method = "REML",
data = month_maxima,
family = gevlss(link = list("identity", "identity", "logit")),
knots = knots,
control = ctrl,
optimizer = "efs")
where the tildes are aligned with one another
If that's not the expected indentation, is there a way to stop the reindention associated with the ~? Assuming that's what is causing the failure to indent subsequent arguments 2 spaces as per the tidyverse style guide?
session info
─ Session info ──────────────────────────────────────────── setting value version R version 4.2.1 (2022-06-23) os Ubuntu 20.04.4 LTS system x86_64, linux-gnu ui X11 language en_GB:en collate en_GB.UTF-8 ctype en_GB.UTF-8 tz Europe/Copenhagen date 2022-07-29 pandoc 2.18 @ /opt/quarto/bin/pandoc─ Packages ────────────────────────────────────────────────
package * version date (UTC) lib source
cli 3.3.0 2022-04-25 [1] RSPM (R 4.2.0)
jsonlite 1.8.0 2022-02-22 [1] RSPM (R 4.2.0)
rlang 1.0.4 2022-07-12 [1] RSPM (R 4.2.1)
sessioninfo 1.2.2 2021-12-06 [1] RSPM (R 4.2.0)[1] /home/au690221/R/x86_64-pc-linux-gnu-library/4.2
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library───────────────────────────────────────────────────────────
Activity
gavinsimpson commentedon Jul 29, 2022
Just to focus in on the
~indentation. This illustrates the intended (?) behaviour with simpler codeproducing
but as soon as we break up the long first formula with a line break, the indentation breaks
yielding
lorenzwalthert commentedon Jul 29, 2022
Ok. Probably not intended but since most people don’t use a non-default scope value, it has not been detected…
gavinsimpson commentedon Aug 1, 2022
@lorenzwalthert Fair enough, but the first example I showed doesn't work as expected with the defaults either:
yielding
lorenzwalthert commentedon Aug 1, 2022
True, then let's fix that as well 😉
lorenzwalthert commentedon Aug 14, 2022
Actually not related to
~, seems like only happens to unnamed arguments:Created on 2022-08-14 by the reprex package (v2.0.1)
gavinsimpson commentedon Aug 25, 2022
That's great; thanks!
gavinsimpson commentedon Feb 7, 2024
As you mentioned that the reported behaviour in the original issue was "probably not intended", I note that the reported behaviour remains in
With
I'm still seeing
whereas with
scope = "tokens"what I think is the desirable formatting is achieved:The simpler version I mentioned also doesn't indent nicely with
scope = "indentation":yields
session info:
Output from
sessioninfo::session_info()