Skip to content

ansi_strtrim() falls over if there's an NA #309

@jennybc

Description

@jennybc

It feels like an NA should just propagate here. I encountered this while implementing a format method (well, technically, a pillar_shaft() method).

x <- month.name
cli::ansi_strtrim(x, width = 3)
#> <ansi_string>
#> [1] Ja… 
#> [2] Fe… 
#> [3] Ma… 
#> [4] Ap… 
#> [5] Ma  
#> [6] Ju… 
#> [7] Ju… 
#> [8] Au… 
#> [9] Se… 
#> [10] Oc…
#> [11] No…
#> [12] De…

x[2] <- NA
cli::ansi_strtrim(x, width = 3)
#> Error in ansi_substr(xt[bad], 1, ansi_nchar(xt[bad]) - 1L): non-numeric substring arguments not supported

Created on 2021-07-06 by the reprex package (v2.0.0.9000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions