Skip to content

Commit

Permalink
Pacify lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Mar 8, 2021
1 parent 02086b8 commit 90af562
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 15 deletions.
9 changes: 9 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
linters: with_defaults(
line_length_linter(120),
commented_code_linter = NULL,
object_usage_linter = NULL,
spaces_left_parentheses_linter = NULL
)
exclude: "# nolint all"
exclude_start: "# nolint start"
exclude_end: "# nolint end"
10 changes: 4 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Color and formatting can now be reliably turned off by setting the `"cli.num_colors"` option to 1 (#269).

## Documentation

- Add examples for new functions (#264).
- Fix lifecycle badges everywhere.

Expand Down Expand Up @@ -228,8 +229,7 @@

# pillar 1.2.1

Display
-------
## Display

- Turned off using subtle style for digits that are considered insignificant. Negative numbers are shown all red. Set the new option `pillar.subtle_num` to `TRUE` to turn it on again (default: `FALSE`).
- The negation sign is printed next to the number again (#91).
Expand All @@ -239,16 +239,14 @@ Display
- The decimal dot is now always printed for numbers of type `numeric`. Trailing zeros are not shown anymore if all displayed numbers are whole numbers (#62).
- Decimal values longer than 13 characters always print in scientific notation.

Bug fixes
---------
# Bug fixes

- Numeric values with a `"class"` attribute (e.g., `Duration` from lubridate) are now formatted using `format()` if the `pillar_shaft()` method is not implemented for that class (#88).
- Very small numbers (like `1e-310`) are now printed correctly (tidyverse/tibble#377).
- Fix representation of right-hand side for `getOption("pillar.sigfig") >= 6` (tidyverse/tibble#380).
- Fix computation of significant figures for numbers with absolute value >= 1 (#98).

New functions
-------------
# New functions

- New styling helper `style_subtle_num()`, formatting depends on the `pillar.subtle_num` option.

Expand Down
2 changes: 2 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#' @import lifecycle
NULL

# nolint start
.onLoad <- function(libname, pkgname) {
# nolint end
# Can't use vctrs::s3_register() here with vctrs 0.1.0
# https://github.com/r-lib/vctrs/pull/314
register_s3_method("knitr", "knit_print", "pillar_squeezed_colonnade")
Expand Down
143 changes: 143 additions & 0 deletions tests/testthat/_snaps/ctl_colonnade.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,149 @@
Code
# dummy

# color, options: UTF-8 is TRUE

Code
style_na("NA")
Output
[1] "\033[31mNA\033[39m"
Code
style_neg("-1")
Output
[1] "\033[31m-1\033[39m"

---

Code
xf <- (function() ctl_colonnade(list(x = c((10^(-3:4)) * c(-1, 1), NA))))
print(xf())
Output
$body
x
<dbl>
1 -0.001
2 0.01
3 -0.1
4 1
5 -10
6 100
7 -1000
8 10000
9 NA
$extra_cols
named list()
Code
with_options(pillar.subtle_num = TRUE, print(xf()))
Output
$body
x
<dbl>
1 -0.001
2 0.01
3 -0.1
4 1
5 -10
6 100
7 -1000
8 10000
9 NA
$extra_cols
named list()
Code
with_options(pillar.subtle = FALSE, print(xf()))
Output
$body
x
<dbl>
1 -0.001
2 0.01
3 -0.1
4 1
5 -10
6 100
7 -1000
8 10000
9 NA
$extra_cols
named list()
Code
with_options(pillar.neg = FALSE, print(xf()))
Output
$body
x
<dbl>
1 -0.001
2 0.01
3 -0.1
4 1
5 -10
6 100
7 -1000
8 10000
9 NA
$extra_cols
named list()
Code
with_options(pillar.subtle = FALSE, pillar.neg = FALSE, print(xf()))
Output
$body
x
<dbl>
1 -0.001
2 0.01
3 -0.1
4 1
5 -10
6 100
7 -1000
8 10000
9 NA
$extra_cols
named list()
Code
with_options(pillar.bold = TRUE, print(xf()))
Output
$body
x
<dbl>
1 -0.001
2 0.01
3 -0.1
4 1
5 -10
6 100
7 -1000
8 10000
9 NA
$extra_cols
named list()

---

Code
ctl_colonnade(list(a_very_long_column_name = 0), width = 20)
Output
$body
a_very_long_colum…
<dbl>
1 0
$extra_cols
named list()

# color, options: UTF-8 is FALSE

Code
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/glimpse.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,22 @@
$ Petal.Width <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.~
$ Species <fct> setosa, setosa, setosa, setosa, setosa, setosa,~
Code
Species <- unique(iris$Species)
species <- unique(iris$Species)
data <- unname(split(iris, iris$Species))
nested_iris_df <- tibble::tibble(Species, data)
nested_iris_df <- tibble::tibble(species, data)
glimpse(nested_iris_df, width = 70L)
Output
Rows: 3
Columns: 2
$ Species <fct> setosa, versicolor, virginica
$ species <fct> setosa, versicolor, virginica
$ data <list> [<data.frame[50 x 5]>], [<data.frame[50 x 5]>], [<da~
Code
data <- map(data, as_tbl)
nested_iris_tbl <- tibble::tibble(Species, data)
nested_iris_tbl <- tibble::tibble(species, data)
glimpse(nested_iris_tbl, width = 70L)
Output
Rows: 3
Columns: 2
$ Species <fct> setosa, versicolor, virginica
$ species <fct> setosa, versicolor, virginica
$ data <list> [<tbl[50 x 5]>], [<tbl[50 x 5]>], [<tbl[50 x 5]>]

2 changes: 2 additions & 0 deletions tests/testthat/test-ctl_colonnade_1.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test_that("strings with varying widths", {
local_options(width = 80)

# Generated by data-raw/create-chr-tests.R
# nolint start
expect_snapshot({
options(width = 59)
ctl_colonnade(df_str[c(12L, 33L, 36L, 7L, 41L, 3L, 18L, 23L, 13L, 44L, 14L, 16L, 25L, 21L, 19L, 45L, 43L, 29L, 1L, 30L, 22L, 27L, 15L, 47L, 28L, 31L, 10L, 50L, 4L, 40L, 42L, 8L, 6L, 9L, 24L, 48L, 38L, 37L, 34L, 49L, 46L, 2L, 32L, 35L, 39L, 11L, 17L, 5L, 26L, 20L)], width = 1382)
Expand Down Expand Up @@ -34,4 +35,5 @@ test_that("strings with varying widths", {
options(width = 46)
ctl_colonnade(df_str[c(38L, 42L, 41L, 10L, 40L, 11L, 27L, 9L, 17L, 37L, 46L, 13L, 36L, 18L, 31L, 20L, 39L, 12L, 44L, 33L, 50L, 34L, 26L, 32L, 23L, 30L, 29L, 21L, 4L, 49L, 19L, 25L, 3L, 6L, 15L, 14L, 43L, 48L, 8L, 22L, 1L, 2L, 45L, 35L, 16L, 5L, 47L, 28L, 24L, 7L)], width = 694)
})
# nolint end
})
2 changes: 2 additions & 0 deletions tests/testthat/test-ctl_colonnade_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test_that("strings with varying widths", {
local_options(width = 80)

# Generated by data-raw/create-chr-tests.R
# nolint start
expect_snapshot({
options(width = 54)
ctl_colonnade(df_str[c(28L, 34L, 16L, 29L, 47L, 25L, 42L, 27L, 44L, 20L, 14L, 36L, 43L, 41L, 26L, 45L, 22L, 9L, 13L, 32L, 31L, 12L, 19L, 48L, 49L, 35L, 3L, 11L, 23L, 24L, 40L, 15L, 38L, 10L, 46L, 5L, 50L, 18L, 21L, 6L, 30L, 2L, 7L, 1L, 4L, 8L, 17L, 33L, 39L, 37L)], width = 516)
Expand Down Expand Up @@ -34,4 +35,5 @@ test_that("strings with varying widths", {
options(width = 41)
ctl_colonnade(df_str[c(22L, 9L, 11L, 26L, 19L, 16L, 32L, 25L, 1L, 30L, 31L, 6L, 24L, 10L, 39L, 21L, 50L, 7L, 29L, 12L, 46L, 43L, 15L, 35L, 20L, 40L, 49L, 38L, 36L, 48L, 34L, 3L, 8L, 4L, 27L, 42L, 44L, 33L, 45L, 18L, 5L, 2L, 13L, 47L, 28L, 17L, 37L, 14L, 41L, 23L)], width = 999)
})
# nolint end
})
7 changes: 6 additions & 1 deletion tests/testthat/test-format_multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ test_that("sanity check (1)", {
})

test_that("output test", {
x <- list(column_zero_one = 1:3 + 0.23, col_02 = letters[1:3], col_03 = factor(letters[1:3]), col_04 = ordered(letters[1:3]))
x <- list(
column_zero_one = 1:3 + 0.23,
col_02 = letters[1:3],
col_03 = factor(letters[1:3]),
col_04 = ordered(letters[1:3])
)
expect_snapshot({
colonnade(x, width = 4)
colonnade(x, width = 5)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-format_multi_fuzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test_that("strings with varying widths", {
local_options(width = 80)

# Generated by data-raw/create-chr-tests.R
# nolint start
expect_snapshot({
options(width = 59)
colonnade(df_str[c(12L, 33L, 36L, 7L, 41L, 3L, 18L, 23L, 13L, 44L, 14L, 16L, 25L, 21L, 19L, 45L, 43L, 29L, 1L, 30L, 22L, 27L, 15L, 47L, 28L, 31L, 10L, 50L, 4L, 40L, 42L, 8L, 6L, 9L, 24L, 48L, 38L, 37L, 34L, 49L, 46L, 2L, 32L, 35L, 39L, 11L, 17L, 5L, 26L, 20L)], width = 1382)
Expand Down Expand Up @@ -34,4 +35,5 @@ test_that("strings with varying widths", {
options(width = 46)
colonnade(df_str[c(38L, 42L, 41L, 10L, 40L, 11L, 27L, 9L, 17L, 37L, 46L, 13L, 36L, 18L, 31L, 20L, 39L, 12L, 44L, 33L, 50L, 34L, 26L, 32L, 23L, 30L, 29L, 21L, 4L, 49L, 19L, 25L, 3L, 6L, 15L, 14L, 43L, 48L, 8L, 22L, 1L, 2L, 45L, 35L, 16L, 5L, 47L, 28L, 24L, 7L)], width = 694)
})
# nolint end
})
2 changes: 2 additions & 0 deletions tests/testthat/test-format_multi_fuzz_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test_that("strings with varying widths", {
local_options(width = 80)

# Generated by data-raw/create-chr-tests.R
# nolint start
expect_snapshot({
options(width = 54)
colonnade(df_str[c(28L, 34L, 16L, 29L, 47L, 25L, 42L, 27L, 44L, 20L, 14L, 36L, 43L, 41L, 26L, 45L, 22L, 9L, 13L, 32L, 31L, 12L, 19L, 48L, 49L, 35L, 3L, 11L, 23L, 24L, 40L, 15L, 38L, 10L, 46L, 5L, 50L, 18L, 21L, 6L, 30L, 2L, 7L, 1L, 4L, 8L, 17L, 33L, 39L, 37L)], width = 516)
Expand Down Expand Up @@ -34,4 +35,5 @@ test_that("strings with varying widths", {
options(width = 41)
colonnade(df_str[c(22L, 9L, 11L, 26L, 19L, 16L, 32L, 25L, 1L, 30L, 31L, 6L, 24L, 10L, 39L, 21L, 50L, 7L, 29L, 12L, 46L, 43L, 15L, 35L, 20L, 40L, 49L, 38L, 36L, 48L, 34L, 3L, 8L, 4L, 27L, 42L, 44L, 33L, 45L, 18L, 5L, 2L, 13L, 47L, 28L, 17L, 37L, 14L, 41L, 23L)], width = 999)
})
# nolint end
})
6 changes: 3 additions & 3 deletions tests/testthat/test-glimpse.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ test_that("output test for glimpse()", {
iris2 <- as_unknown_rows(iris)
glimpse(iris2, width = 70L)

Species <- unique(iris$Species)
species <- unique(iris$Species)
data <- unname(split(iris, iris$Species))
nested_iris_df <- tibble::tibble(Species, data)
nested_iris_df <- tibble::tibble(species, data)
glimpse(nested_iris_df, width = 70L)

data <- map(data, as_tbl)
nested_iris_tbl <- tibble::tibble(Species, data)
nested_iris_tbl <- tibble::tibble(species, data)
glimpse(nested_iris_tbl, width = 70L)
})
})

0 comments on commit 90af562

Please sign in to comment.