Skip to content

Problems in plot.sf after a failed plot - plot window does not get resetted #2519

@agila5

Description

@agila5

Describe the bug
See the reprex(es) below.

To Reproduce

library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE

# Default behaviour: st_geometry(nc) is plotted in a new window
nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE)
plot(nc[, 1:7])

plot(st_geometry(nc))

# Now I will add a "faulty" list column to nc and repeat the same code as before
nc[[7]] <- vector("list", 100)
plot(nc[, 1:7])
#> Error in plot.sf(x[, cname], main = cname, pal = pal, nbreaks = nbreaks, : plotting list-columns not supported
plot(st_geometry(nc)) # Plotted in the same plot

Created on 2025-04-09 with reprex v2.1.1.9000

Another example of problematic interaction:

library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE

# Default behaviour: st_geometry(nc) is plotted in a new window
nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE)

# Now I will add a "faulty" list column to nc and repeat the same code as before
nc[[7]] <- vector("list", 100)
plot(nc[, 1:7])
#> Error in plot.sf(x[, cname], main = cname, pal = pal, nbreaks = nbreaks, : plotting list-columns not supported

# Revert back the faulty column
nc[[7]] <- rnorm(100)
plot(nc[, 1:7])
plot(st_geometry(nc)) # Plotted in a weird format

Created on 2025-04-09 with reprex v2.1.1.9000

Session info
sessioninfo::session_info()
#> Warning in system2("quarto", "-V", stdout = TRUE, env = paste0("TMPDIR=", :
#> running command '"quarto"
#> TMPDIR=C:/Users/andre/AppData/Local/Temp/RtmpkJkWEx/file5aac187723a1 -V' had
#> status 1
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.2 (2024-10-31 ucrt)
#>  os       Windows 11 x64 (build 26100)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  Italian_Italy.utf8
#>  ctype    Italian_Italy.utf8
#>  tz       Europe/Rome
#>  date     2025-04-09
#>  pandoc   3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#>  quarto   NA @ C:\\Users\\andre\\AppData\\Local\\Programs\\Quarto\\bin\\quarto.exe
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  class         7.3-22     2023-05-03 [2] CRAN (R 4.4.2)
#>  classInt      0.4-11     2025-01-08 [1] CRAN (R 4.4.2)
#>  cli           3.6.4      2025-02-13 [1] CRAN (R 4.4.3)
#>  curl          6.2.1      2025-02-19 [1] CRAN (R 4.4.2)
#>  DBI           1.2.3      2024-06-02 [1] CRAN (R 4.4.2)
#>  digest        0.6.37     2024-08-19 [1] CRAN (R 4.4.2)
#>  e1071         1.7-16     2024-09-16 [1] CRAN (R 4.4.2)
#>  evaluate      1.0.3      2025-01-10 [1] CRAN (R 4.4.2)
#>  fastmap       1.2.0      2024-05-15 [1] CRAN (R 4.4.2)
#>  fs            1.6.5      2024-10-30 [1] CRAN (R 4.4.2)
#>  glue          1.8.0      2024-09-30 [1] CRAN (R 4.4.2)
#>  htmltools     0.5.8.1    2024-04-04 [1] CRAN (R 4.4.2)
#>  KernSmooth    2.23-24    2024-05-17 [2] CRAN (R 4.4.2)
#>  knitr         1.49       2024-11-08 [1] CRAN (R 4.4.2)
#>  lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.4.2)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.4.2)
#>  proxy         0.4-27     2022-06-09 [1] CRAN (R 4.4.2)
#>  Rcpp          1.0.14     2025-01-12 [1] CRAN (R 4.4.2)
#>  reprex        2.1.1.9000 2025-02-25 [1] Github (tidyverse/reprex@07cd5d7)
#>  rlang         1.1.5      2025-01-17 [1] CRAN (R 4.4.2)
#>  rmarkdown     2.29       2024-11-04 [1] CRAN (R 4.4.2)
#>  rstudioapi    0.17.1     2024-10-22 [1] CRAN (R 4.4.2)
#>  sessioninfo   1.2.3      2025-02-05 [1] CRAN (R 4.4.2)
#>  sf          * 1.0-21     2025-04-09 [1] Github (r-spatial/sf@ac49ec2)
#>  units         0.8-7.1    2025-04-09 [1] Github (r-quantities/units@3fa5ae6)
#>  withr         3.0.2      2024-10-28 [1] CRAN (R 4.4.2)
#>  xfun          0.51.2     2025-02-20 [1] https://yihui.r-universe.dev (R 4.4.2)
#>  xml2          1.3.6      2023-12-04 [1] CRAN (R 4.4.2)
#>  yaml          2.3.10     2024-07-26 [1] CRAN (R 4.4.2)
#> 
#>  [1] C:/Users/andre/AppData/Local/R/win-library/4.4
#>  [2] C:/Program Files/R/R-4.4.2/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions