Skip to content

Saving to svg without svglite installed throws unhelpful error #6166

Closed
@eliocamp

Description

@eliocamp

Trying to save a plot to svg without svsglite installed (which is possible because svglite is a Suggest) throws this error:

> ggsave("poster.svg")
Saving 7 x 7 in imageError in loadNamespace(x) : there is no package called ‘svglite’

The error is not very helpful as it doesn't tell the user what the issue is and how to resolve it.

The problem is that plot_dev doesn't check if svglite is installed here:

svg = function(filename, ...) svglite::svglite(file = filename, ...),

so R errors out when trying to evaluate the dev function; probably here:

dev(filename = filename, width = dim[1], height = dim[2], bg = bg, ...)

Maybe a better alternative would be to do something like this:

svg =  function(filename, ...) { 
   check_installed("svglite", reason = "to save as SVG.")
   svglite::svglite(file = filename, ...)
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    messagesrequests for improvements to error, warning, or feedback messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions