Skip to content

Improve error message when a list containing empty vectors is passed to legend.grob() #167

@tnyamaguchi

Description

@tnyamaguchi

when print(legend.empty) is

$levels
character(0)

$colours
character(0)

due to a user error,

legend.test<- list(
    legend = list(
        colours = legend.empty$colours,
        labels = legend.empty$levels,
        title = expression(bold(underline('Test'))),
        lwd = 0.5
        ),
     legend = list(...   
        );

bitmap.type = getOption('bitmapType')
if (capabilities('cairo')) {
    bitmap.type <- 'cairo';
    }

# create a legend grob using defaults
legend.grob1 <- legend.grob(
    legends = legend.test
    );

tiff(
    filename = "test.png",
    type = bitmap.type,
    width = 2,
    height = 10,
    units = 'in',
    res = 800,
    compression = 'lzw'
    );
grid.draw(legend.grob1);

will fail. The getCharCE error message is not helpful to identify the issue. Maybe consider making the warning an error here?

Warning messages:
1: In FUN(X[[i]], ...) : 'x' is NULL so the result will be NULL
2: In FUN(X[[i]], ...) : 'x' is NULL so the result will be NULL
3: In FUN(X[[i]], ...) : 'x' is NULL so the result will be NULL
4: In FUN(X[[i]], ...) : 'x' is NULL so the result will be NULL
5: In FUN(X[[i]], ...) : 'x' is NULL so the result will be NULL
6: In FUN(X[[i]], ...) : 'x' is NULL so the result will be NULL
7: In FUN(X[[i]], ...) : 'x' is NULL so the result will be NULL
8: In FUN(X[[i]], ...) : 'x' is NULL so the result will be NULL
Error in grid.Call.graphics(C_setviewport, vp, TRUE) :
  'getCharCE' must be called on a CHARSXP
Calls: grid.draw ... lapply -> FUN -> push.vp.viewport -> grid.Call.graphics
Execution halted

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions