From ace77d2f584d29ca29a704ec8dba125d8f77042b Mon Sep 17 00:00:00 2001 From: Matt Dray <18232097+matt-dray@users.noreply.github.com> Date: Sat, 8 Mar 2025 17:19:34 +0000 Subject: [PATCH 1/3] Add antialias, cairo --- R/hexagon.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/hexagon.R b/R/hexagon.R index 29a3d8c..4a0759f 100644 --- a/R/hexagon.R +++ b/R/hexagon.R @@ -57,7 +57,9 @@ open_device <- function(file_path, resolution = 300) { height = 5.08, units = "cm", res = resolution, - bg = "transparent" + bg = "transparent", + type = "cairo", + antialias = "none" ) } From 9bb4aac19d716b73692e52f2e55d309211ddbfc6 Mon Sep 17 00:00:00 2001 From: Matt Dray <18232097+matt-dray@users.noreply.github.com> Date: Sat, 8 Mar 2025 17:22:04 +0000 Subject: [PATCH 2/3] Add blog badge, Windows system start --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b1076c..4fea869 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![R-CMD-check](https://github.com/matt-dray/gex/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/matt-dray/gex/actions/workflows/R-CMD-check.yaml) +[![Blog posts](https://img.shields.io/badge/rostrum.blog-posts-008900?labelColor=000000&logo=data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhEAAQAPEAAAAAABWCBAAAAAAAACH5BAlkAAIAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAAQAAAC55QkISIiEoQQQgghRBBCiCAIgiAIgiAIQiAIgSAIgiAIQiAIgRAEQiAQBAQCgUAQEAQEgYAgIAgIBAKBQBAQCAKBQEAgCAgEAoFAIAgEBAKBIBAQCAQCgUAgEAgCgUBAICAgICAgIBAgEBAgEBAgEBAgECAgICAgECAQIBAQIBAgECAgICAgICAgECAQECAQICAgICAgICAgEBAgEBAgEBAgICAgICAgECAQIBAQIBAgECAgICAgIBAgECAQECAQIBAgICAgIBAgIBAgEBAgECAgECAgICAgICAgECAgECAgQIAAAQIKAAAh%2BQQJZAACACwAAAAAEAAQAAAC55QkIiESIoQQQgghhAhCBCEIgiAIgiAIQiAIgSAIgiAIQiAIgRAEQiAQBAQCgUAQEAQEgYAgIAgIBAKBQBAQCAKBQEAgCAgEAoFAIAgEBAKBIBAQCAQCgUAgEAgCgUBAICAgICAgIBAgEBAgEBAgEBAgECAgICAgECAQIBAQIBAgECAgICAgICAgECAQECAQICAgICAgICAgEBAgEBAgEBAgICAgICAgECAQIBAQIBAgECAgICAgIBAgECAQECAQIBAgICAgIBAgIBAgEBAgECAgECAgICAgICAgECAgECAgQIAAAQIKAAA7)](https://www.rostrum.blog/index.html#category=gex) ## What @@ -95,13 +96,15 @@ That creates this absolutely stunning demo sticker, written to the specified `fi Note that you can't rely on plot-window previews when you're developing your sticker (they lie). You must inspect the generated PNG file instead. -From R, you could do this with a `system()` call: +You could do this with a `system()` call from R: ``` r # Open the PNG hex image for inspection system(paste("open", temp_path)) ``` +Try `start` rather than `open` on Windows. + ## Related For more established hex-making tools with R, try: From 149e4ec988a87389d7f0e1c93aa97a7178a61553 Mon Sep 17 00:00:00 2001 From: Matt Dray <18232097+matt-dray@users.noreply.github.com> Date: Sat, 8 Mar 2025 17:50:39 +0000 Subject: [PATCH 3/3] Set type/antialias in graphics device if windows --- R/hexagon.R | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/R/hexagon.R b/R/hexagon.R index 4a0759f..31e0f11 100644 --- a/R/hexagon.R +++ b/R/hexagon.R @@ -51,16 +51,27 @@ open_device <- function(file_path, resolution = 300) { stop("Argument 'resolution' must be a numeric value.", call. = FALSE) } - grDevices::png( - filename = file_path, - width = 4.39, - height = 5.08, - units = "cm", - res = resolution, - bg = "transparent", - type = "cairo", - antialias = "none" - ) + if (.Platform[["OS.type"]] == "windows") { + grDevices::png( + filename = file_path, + width = 4.39, + height = 5.08, + units = "cm", + res = resolution, + bg = "transparent", + type = "cairo", + antialias = "none" + ) + } else { + grDevices::png( + filename = file_path, + width = 4.39, + height = 5.08, + units = "cm", + res = resolution, + bg = "transparent" + ) + } }