wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
651 stars 37 forks source link

ggtext boxplot example fails on Windows #35

Closed EarlGlynn closed 4 years ago

EarlGlynn commented 4 years ago

The iris boxplot example from https://wilkelab.org/ggtext/ fails on Windows in the ggplot statement. Is this a known problem?

38.     fun(structure(list(message = msg, call = sys.call()), class = c(typeName, "GenericCurlError", "error", "condition")))
37.     function (type, msg, asError = TRUE) { if (!is.character(type)) { i = match(type, CURLcodeValues) ...
36.     curlPerform(curl = curl, .opts = opts, .encoding = .encoding)
35.     getURL(url, ..., write = getNativeSymbolInfo("R_curl_write_binary_data")$address, file = .buf@ref, curl = curl, .opts = .opts)
34.     RCurl::getBinaryURL(path)
33.     get_file(path)
32.     jpeg::readJPEG(get_file(path), native = TRUE)
31.     read_image(attr$src)
30.     process_tag_img(node, drawing_context)
29.     dispatch_tag(node[[i]], tags[i], drawing_context)
28.     process_tags(node, drawing_context)
27.     unlist(list(process_tags(node, drawing_context), process_tag_br(NULL, drawing_context)), recursive = FALSE)
26.     process_tag_p(node, drawing_context)
25.     dispatch_tag(node[[i]], tags[i], drawing_context)
24.     process_tags(xml2::as_list(doctree)$html$body, drawing_context)
23.     (function (text, halign, valign, use_markdown, gp) { if (use_markdown) { text <- markdown::markdownToHTML(text = text, options = c("use_xhtml", ...
22.     mapply(make_inner_box, text, halign, valign, use_markdown, gp_list, SIMPLIFY = FALSE)
21.     richtext_grob(label, x = x, y = y, hjust = hj, vjust = vj, halign = halign, valign = valign, rot = angle, padding = padding, margin = mrg$margin, r = r, align_widths = align_widths, align_heights = align_heights, gp = gp, box_gp = box_gp, debug = element$debug)
20.     element_grob.element_markdown(structure(list(family = "", face = "plain", size = 11, colour = "black", fill = NULL, box.colour = NULL, linetype = NULL, linewidth = NULL, hjust = 0.5, vjust = 1, halign = NULL, valign = NULL, angle = 0, lineheight = 0.9, ...
19.     (function (element, ...) { UseMethod("element_grob") })(structure(list(family = "", face = "plain", size = 11, colour = "black", ...
18.     exec(element_grob, label_element, `:=`(!!position_dim, break_positions), `:=`(!!label_margin_name, TRUE), label = break_labels, check.overlap = check.overlap)
17.     draw_axis_labels(break_positions = break_positions[indices], break_labels = break_labels[indices], label_element = label_element, is_vertical = is_vertical, check.overlap = check.overlap)
16.     FUN(X[[i]], ...)
15.     lapply(dodge_indices, function(indices) { draw_axis_labels(break_positions = break_positions[indices], break_labels = break_labels[indices], label_element = label_element, is_vertical = is_vertical, check.overlap = check.overlap) ...
14.     draw_axis(break_positions = guide$key[[aesthetic]], break_labels = guide$key$.label, axis_position = guide$position, theme = theme, check.overlap = guide$check.overlap, angle = guide$angle, n.dodge = guide$n.dodge)
13.     guide_gengrob.axis(guide, theme)
12.     guide_gengrob(guide, theme)
11.     panel_guides_grob(panel_params$guides, position = "bottom", theme = theme)
10.     f(...)
9.      coord$render_axis_h(range, theme)
8.      f(...)
7.      self$facet$draw_panels(panels, self$layout, self$panel_scales_x, self$panel_scales_y, self$panel_params, self$coord, data, theme, self$facet_params)
6.      f(..., self = self)
5.      layout$render(geom_grobs, data, theme, plot$labels)
4.      ggplot_gtable.ggplot_built(data)
3.      ggplot_gtable(data)
2.      print.ggplot(x)
1.      (function (x, ...) UseMethod("print"))(x)

Could you publish your sessionInfo() with your examples? Perhaps this is a Windows - Mac difference, since Windows can be a bit fickle with RCurl?

Here's my sessionInfo:

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
 [1] glue_1.4.1      ggtext_0.1.0    ggcharts_0.2.1  forcats_0.5.0   stringr_1.4.0
 [6] dplyr_0.8.5     purrr_0.3.4     readr_1.3.1     tidyr_1.0.3     tibble_3.0.1
[11] ggplot2_3.3.0   tidyverse_1.3.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6        lubridate_1.7.8     lattice_0.20-41     assertthat_0.2.1
 [5] digest_0.6.25       R6_2.4.1            cellranger_1.1.0    backports_1.1.6
 [9] reprex_0.3.0        httr_1.4.1          pillar_1.4.4        rlang_0.4.6
[13] curl_4.3            readxl_1.3.1        rstudioapi_0.11     labeling_0.3
[17] RCurl_1.98-1.2      munsell_0.5.0       gridtext_0.1.1      broom_0.5.6
[21] compiler_3.6.0      modelr_0.1.7        xfun_0.14           pkgconfig_2.0.3
[25] htmltools_0.4.0     tidyselect_1.0.0    fansi_0.4.1         crayon_1.3.4
[29] dbplyr_1.4.3        withr_2.2.0         bitops_1.0-6        grid_3.6.0
[33] nlme_3.1-147        jsonlite_1.6.1      gtable_0.3.0        lifecycle_0.2.0
[37] DBI_1.1.0           magrittr_1.5        scales_1.1.1        cli_2.0.2
[41] stringi_1.4.6       farver_2.0.3        fs_1.4.1            remotes_2.1.1
[45] xml2_1.3.2          ellipsis_0.3.0      generics_0.0.2      vctrs_0.2.4
[49] tools_3.6.0         markdown_1.1        hms_0.5.3           jpeg_0.1-8.1
[53] colorspace_1.4-1    mdthemes_0.0.0.9000 rvest_0.3.5         knitr_1.28
[57] haven_2.2.0         patchwork_1.0.0
clauswilke commented 4 years ago

Does this code run for you?

files <- c(
  "https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Iris_setosa.JPG/180px-Iris_setosa.JPG",
  "https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Iris_virginica_-_NRCS.jpg/320px-Iris_virginica_-_NRCS.jpg",
  "https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/20140427Iris_versicolor1.jpg/320px-20140427Iris_versicolor1.jpg"
)

imgs <- lapply(files, function(x) {
  print(x)
  RCurl::getBinaryURL(x)
})
#> [1] "https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Iris_setosa.JPG/180px-Iris_setosa.JPG"
#> [1] "https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Iris_virginica_-_NRCS.jpg/320px-Iris_virginica_-_NRCS.jpg"
#> [1] "https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/20140427Iris_versicolor1.jpg/320px-20140427Iris_versicolor1.jpg"

Created on 2020-05-25 by the reprex package (v0.3.0)

thomas-neitmann commented 4 years ago

I can confirm the observation of @EarlGlynn when running R 3.6.3 on Windows 10 x64 (build 17763).

Error in function (type, msg, asError = TRUE)  : 
  error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

@clauswilke The code you posted produces the same error.

clauswilke commented 4 years ago

There's nothing I can do about this then. Looks like RCurl fails on Windows, maybe because the URL uses the https protocol. You could always work around the problem by downloading the images to your local drive and then using local file paths instead of URLs.

EarlGlynn commented 4 years ago

curl and RCurl historically have been a problem with Windows. But curl works fine from a command line in Windows now -- but I'm not sure exactly what RCurl does and why it's failing.

curl https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Iris_setosa.JPG/180px-Iris_setosa.JPG -o x.jpg

The following gets the example to work in Windows using your files from above to copy the files locally, and modifying the labels from your example:

lapply(files, function(x) {download.file(x, basename(x), mode="wb")})
labels <- c(
  setosa = "<img src='180px-Iris_setosa.JPG'
    width='100' /><br>*I. setosa*",
  virginica = "<img src='320px-Iris_virginica_-_NRCS.jpg'
    width='100' /><br>*I. virginica*",
  versicolor = "<img src='320px-20140427Iris_versicolor1.jpg'
    width='100' /><br>*I. versicolor*"

Your ggplot with element_markdown works fine now on Windows and displays the iris images with species name in italics!

ggtext will be quite useful.