diff --git a/.Rbuildignore b/.Rbuildignore
index 0ff1239..b736d15 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -3,3 +3,4 @@
^LICENSE\.md$
^\.github$
^CODEOWNERS$
+^data-raw$
diff --git a/NEWS.md b/NEWS.md
index 9327a95..a75abf4 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,6 +1,7 @@
# gex 0.2.0.9000
* Added hex logo for the package.
+* Added 'resolution' argument to `open_device()`.
# gex 0.2.0
diff --git a/R/hexagon.R b/R/hexagon.R
index 760f9e1..29a3d8c 100644
--- a/R/hexagon.R
+++ b/R/hexagon.R
@@ -6,6 +6,9 @@
#'
#' @param file_path Character. File path to a .png where the output file will be
#' saved. The containing directory must already exist.
+#' @param resolution Numeric. Resolution of the graphics device in pixels per
+#' inch (ppi). Higher values have better resolution but create larger file
+#' sizes.
#'
#' @details
#'
@@ -31,7 +34,7 @@
#' add_text()
#' add_border()
#' close_device()
-open_device <- function(file_path) {
+open_device <- function(file_path, resolution = 300) {
if (tools::file_ext(file_path) != "png") {
stop("Argument 'file_path' must end with '.png'.", call. = FALSE)
@@ -44,12 +47,16 @@ open_device <- function(file_path) {
)
}
+ if (!inherits(resolution, "numeric")) {
+ stop("Argument 'resolution' must be a numeric value.", call. = FALSE)
+ }
+
grDevices::png(
filename = file_path,
width = 4.39,
height = 5.08,
units = "cm",
- res = 1200,
+ res = resolution,
bg = "transparent"
)
diff --git a/README.md b/README.md
index b2b7aab..4b1076c 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# {gex}
+# {gex}
[](https://www.repostatus.org/#active)
@@ -58,7 +58,10 @@ image_path <- system.file("img", "Rlogo.png", package = "png")
image_png <- png::readPNG(image_path)
# Build and write the hex
-gex::open_device(file_path = temp_path)
+gex::open_device(
+ file_path = temp_path,
+ resolution = 300 # ppi, you can increase this
+)
gex::add_hex(col = "#BEBEBE") # named or hexadecimal
gex::add_image(
img = image_png,
@@ -86,9 +89,9 @@ gex::add_border(col = "grey20")
gex::close_device() # writes to file
```
-That creates this absolutely stunning sticker, written to the specified `file_path`:
+That creates this absolutely stunning demo sticker, written to the specified `file_path`:
-
+
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.
diff --git a/inst/tinytest/test_gex.R b/inst/tinytest/test_gex.R
index 6d8d55e..4c80b6b 100644
--- a/inst/tinytest/test_gex.R
+++ b/inst/tinytest/test_gex.R
@@ -9,7 +9,6 @@ dev_open <- open_device(temp_path)
expect_null(dev_open)
dev_close <- dev.off()
expect_true(is.numeric(dev_close))
-unlink(temp_path)
err_arg <- 'argument "file_path" is missing, with no default'
expect_error(open_device(), err_arg)
@@ -22,6 +21,11 @@ expect_error(open_device("x/y.pdf"), err_png)
err_dir <- "Argument 'file_path' must resolve to an existing directory\\."
expect_error(open_device("x/y/z.png", err_dir))
+err_res <- "Argument 'resolution' must be a numeric value\\."
+expect_error(open_device(temp_path, resolution = "x"), err_res)
+
+unlink(temp_path)
+
# Add hex -----------------------------------------------------------------
hex <- add_hex()
diff --git a/man/figures/example.png b/man/figures/example.png
new file mode 100644
index 0000000..4bf47b1
Binary files /dev/null and b/man/figures/example.png differ
diff --git a/man/figures/logo.png b/man/figures/logo.png
index f416aa3..04055ef 100644
Binary files a/man/figures/logo.png and b/man/figures/logo.png differ
diff --git a/man/figures/readme-hex.png b/man/figures/readme-hex.png
deleted file mode 100644
index 61ed615..0000000
Binary files a/man/figures/readme-hex.png and /dev/null differ
diff --git a/man/open_device.Rd b/man/open_device.Rd
index 8db1321..47f1ad6 100644
--- a/man/open_device.Rd
+++ b/man/open_device.Rd
@@ -4,11 +4,15 @@
\alias{open_device}
\title{Open a PNG Device with Sticker-Standard Dimensions}
\usage{
-open_device(file_path)
+open_device(file_path, resolution = 300)
}
\arguments{
\item{file_path}{Character. File path to a .png where the output file will be
saved. The containing directory must already exist.}
+
+\item{resolution}{Numeric. Resolution of the graphics device in pixels per
+inch (ppi). Higher values have better resolution but create larger file
+sizes.}
}
\value{
Nothing. A graphics device is opened.