You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right... I was wondering about assertive tests in general. I used checkmate but I can't really remember why not having choosed assertr, assertive or assertthat. Any preference on your side?
There actually exists a check in tidyverse_style(scope = "...") when the ordered factor is created from scope.
cat(styler::style_text("a", scope="abc"), sep="\n")
#> Error in character_to_ordered(scope, c("none", "spaces", "indention", : all values in scope must be one of the following: none, spaces, indention, line_breaks, tokens
Note that style_text() does use utf8::transform_lines_enc(), which itself implements some error handling.
Styling one file also seems to work (at least outside the stylerRproj):
> style_file("/Users/lorenz/Documents/short-term back-up/assertive.R", scope="3")
#> Styling 1 files:#> assertive.R. [DONE]#> No files changed.#> Warning message:#>" When processing assertive.R: all values in scope must be one of the following: none, spaces, #> indention, line_breaks, tokens
But as you said, an error occurs with style_pkg() and also style_dir(). I don't understand why though... It also gives the "[...] all values in scope must be one of the following: none, spaces, indention, line_breaks, tokens [...]" warning, but it seems as execution is continued, which then produces these warnings: "In reduce_index(.x, .init, left = .left) :"
Well it is already constructed before the body of the style_text() and friends is executed. However, we could use force(transformers) in the closure make_transformers() to solve the problem. Not sure whether there are more elegant ways but this approach seems to works.
I think in the end we need to force transformers, since style is only used to create transformers by default and you actually don't need to supply the argument. I thought about that too but isn't that a bit redundant? What's the advantage to call it in every style* function over calling it once?
Activity
lorenzwalthert commentedon Aug 31, 2017
Right... I was wondering about assertive tests in general. I used
checkmatebut I can't really remember why not having choosedassertr,assertiveorassertthat. Any preference on your side?krlmlr commentedon Aug 31, 2017
A simple
match.arg()would suffice here IMO.lorenzwalthert commentedon Aug 31, 2017
So just for
scopeor systematically for all arguments in all exported functions?krlmlr commentedon Aug 31, 2017
We should apply stricter argument checking everywhere, but
scopeseems more urgent because it does the wrong thing if the value has a typo.lorenzwalthert commentedon Sep 1, 2017
There actually exists a check in
tidyverse_style(scope = "...")when the ordered factor is created fromscope.Note that
style_text()does useutf8::transform_lines_enc(), which itself implements some error handling.Styling one file also seems to work (at least outside the
stylerRproj):But as you said, an error occurs with
style_pkg()and alsostyle_dir(). I don't understand why though... It also gives the "[...] all values in scope must be one of the following: none, spaces, indention, line_breaks, tokens [...]" warning, but it seems as execution is continued, which then produces these warnings: "In reduce_index(.x, .init, left = .left) :"lorenzwalthert commentedon Sep 1, 2017
Implementing the
scopecheck at the point where we create the ordered factor, i.e. intidyverse_style()seems to be the right place to me though.lorenzwalthert commentedon Sep 2, 2017
@krlmlr any ideas fro your side?
krlmlr commentedon Sep 2, 2017
Maybe construct the style guide object early on, before calling
transform_files...()?lorenzwalthert commentedon Sep 2, 2017
Well it is already constructed before the body of the style_text() and friends is executed. However, we could use force(transformers) in the closure make_transformers() to solve the problem. Not sure whether there are more elegant ways but this approach seems to works.
krlmlr commentedon Sep 2, 2017
Yes, lazy evaluation bites sometimes. I'd suggest to
force(style)in each interface function.lorenzwalthert commentedon Sep 2, 2017
I think in the end we need to force transformers, since style is only used to create transformers by default and you actually don't need to supply the argument. I thought about that too but isn't that a bit redundant? What's the advantage to call it in every style* function over calling it once?
krlmlr commentedon Sep 2, 2017
A
force()call inmake_transformer()seems sufficient too.