From e52494b341bc9238e95e8a17e9fdef10e2c06629 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 29 Nov 2023 16:05:29 +0100 Subject: [PATCH] fixes key.width issue --- R/plot.R | 14 +++++++++----- tests/plot.Rout.save | 8 +++++--- tests/read.Rout.save | 12 ++++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/R/plot.R b/R/plot.R index 8eb7eb12f..cf8db5dff 100644 --- a/R/plot.R +++ b/R/plot.R @@ -1,15 +1,19 @@ kw_dflt = function(x, key.pos) { - if (is.null(key.pos) || key.pos <= 0) - lcm(0) + if (is.null(key.pos) || key.pos == 0) # no key: + return(lcm(0)) + + font_scale = par("ps") / 12 + if (key.pos == -1) + lcm(1.8 * font_scale) else if (key.pos %in% c(2, 4) && (is.character(x[[1]]) || is.factor(x[[1]]))) { strings = if (is.factor(x[[1]])) levels(x[[1]]) else x[[1]] - lcm(cm(max(strwidth(strings, "inches"))) * 1.3 + par("ps")/12) # cm + lcm(cm(max(strwidth(strings, "inches"))) * 1.3 + font_scale) # cm + #lcm(cm(max(strwidth(strings, "inches"))) * 1.3) # cm } else - # lcm(1.8 * par("ps")/12) - lcm(1.8) + lcm(1.8 * font_scale) } diff --git a/tests/plot.Rout.save b/tests/plot.Rout.save index 70a14583a..ac02c2a8d 100644 --- a/tests/plot.Rout.save +++ b/tests/plot.Rout.save @@ -1,5 +1,5 @@ -R version 4.3.1 (2023-06-16) -- "Beagle Scouts" +R version 4.3.2 (2023-10-31) -- "Eye Holes" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) @@ -88,9 +88,11 @@ Type 'q()' to quit R. + plot(nc, axes = TRUE) + plot(nc, col="lightgrey") + plot(st_centroid(nc), add = TRUE, col = 1) -+ nc %>% ++ if ("geometry" %in% names(nc)) { ++ nc %>% + select(geometry) %>% + plot() ++ } + + nc$f = cut(nc[[1]], 5) + plot(nc["f"], key.pos = 1) @@ -150,4 +152,4 @@ There were 13 warnings (use warnings() to see them) > > proc.time() user system elapsed - 4.822 0.828 4.857 + 3.111 1.417 3.015 diff --git a/tests/read.Rout.save b/tests/read.Rout.save index b205051da..f638cd33a 100644 --- a/tests/read.Rout.save +++ b/tests/read.Rout.save @@ -1,6 +1,6 @@ -R version 4.2.2 Patched (2022-11-10 r83330) -- "Innocent and Trusting" -Copyright (C) 2022 The R Foundation for Statistical Computing +R version 4.3.2 (2023-10-31) -- "Eye Holes" +Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. @@ -327,10 +327,10 @@ First 3 features: > > if ("GML" %in% st_drivers()$name) { + gml = system.file("gml/fmi_test.gml", package = "sf") -+ print(dim(st_read(gml, quiet = TRUE))) ++ print(dim(st_read(gml, quiet = TRUE, use_stream = FALSE))) + gml = system.file("gml/20170930_OB_530964_UKSH.xml.gz", package = "sf") -+ print(dim(st_read(gml, layer = "Parcely", quiet = TRUE))) -+ print(dim(st_read(gml, layer = "Parcely", int64_as_string=TRUE, quiet = TRUE))) ++ print(dim(st_read(gml, layer = "Parcely", quiet = TRUE, use_stream = FALSE))) ++ print(dim(st_read(gml, layer = "Parcely", int64_as_string=TRUE, quiet = TRUE, use_stream = FALSE))) + } [1] 22 11 [1] 644 25 @@ -376,4 +376,4 @@ Error : wkt parse error. > > proc.time() user system elapsed - 2.288 0.818 2.281 + 1.255 1.397 1.179