Skip to content

Commit

Permalink
version 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
clauswilke authored and cran-robot committed Feb 24, 2020
1 parent 88d3845 commit 6c6d9d6
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 31 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: gridtext
Type: Package
Title: Improved Text Rendering Support for 'Grid' Graphics
Version: 0.1.0
Version: 0.1.1
Authors@R:
person(
given = "Claus O.",
Expand All @@ -26,8 +26,8 @@ LazyData: true
RoxygenNote: 7.0.2
SystemRequirements: C++11
NeedsCompilation: yes
Packaged: 2020-01-16 18:37:10 UTC; clauswilke
Packaged: 2020-02-24 22:25:25 UTC; clauswilke
Author: Claus O. Wilke [aut, cre] (<https://orcid.org/0000-0002-7470-9261>)
Maintainer: Claus O. Wilke <wilke@austin.utexas.edu>
Repository: CRAN
Date/Publication: 2020-01-24 17:30:02 UTC
Date/Publication: 2020-02-24 22:40:02 UTC
18 changes: 9 additions & 9 deletions MD5
@@ -1,7 +1,7 @@
f5708889ca4f0a9a29ebb53c6f9e6037 *DESCRIPTION
d052f5732ab707d1b5303b87c42a5f48 *DESCRIPTION
39276fab68fb6f733821e2f243383213 *LICENSE
0857ec650ec6eaebb76f061ff2d67a68 *NAMESPACE
aa7a4cb0eeecc0281a2dacf613938f2a *NEWS.md
d762ea907af19ce3d77c107e5c5e1023 *NEWS.md
b35088f9df099335362baa60c94fabb9 *R/RcppExports.R
bfbf62c0341836a598bf9c4efc728199 *R/catch-routine-registration.R
4527d6b21d7c1bb4691dde35ee928398 *R/drawing-context.R
Expand All @@ -12,10 +12,10 @@ d441b7c0ec23dc1e813e4efc421e4c62 *R/grob-zero.R
6f2fdb69ac961039af6d814b61dae5d0 *R/process-tags.R
ce37c3f6ac753f22d2a04ec8c9d4a965 *R/read-image.R
14f402b6578dc90c2ccc237fd5985d9a *R/recycle-gpar.R
de07accef40aea5fde11d6f795d4c4c6 *R/richtext-grob.R
78d868e02a776fa994f8ef9c1b0c35f2 *R/richtext-grob.R
993e909e3ca88ea9454c1b6c307fd560 *R/text-details.R
ff0ace7f0b430bf47c7eb84f47478f45 *R/textbox-grob.R
ab3e39d895f6fd0e7234a68d66f445ab *README.md
ae1de5b7a593c80a20591170df9d89c1 *R/textbox-grob.R
c21aaf093bc5187b9483e861c9916a01 *README.md
a424816ce3f3342cdd6254853ef2ff55 *inst/extdata/Rlogo.png
e3095ff8a05aa032723f89f2573c2096 *man/figures/README-unnamed-chunk-4-1.png
fd7571699e1734d3cfcf7aa8ad844e92 *man/figures/README-unnamed-chunk-5-1.png
Expand All @@ -30,7 +30,7 @@ b768a47be0be837939ac29e35472f98e *src/bl-r-bindings.cpp
d269719f4d854f1631ef0855544996c2 *src/glue.h
37903129a8e47d97fe238f007c62fd75 *src/grid-renderer.cpp
86aeb8f8c4adcbde508769c3489518aa *src/grid-renderer.h
e9003b9fa59db65cb4021f1c4ee1b8e2 *src/grid.cpp
7281f599adafac6197f3922bcaf8e59d *src/grid.cpp
0f83d99b161de0acd132a795b22061be *src/grid.h
b2687846d89a7cf50e9981e1b027780e *src/gridtext_types.h
fe9e6d3d255267f5c38d99d167b434e9 *src/layout.h
Expand Down Expand Up @@ -65,14 +65,14 @@ f2d116c67913c1bbb2c946c4fd631ffd *tests/figs/textbox-grob/multiple-boxes-left-ro
8d90a80333398e45985b4afd082bd7dc *tests/figs/textbox-grob/multiple-boxes-right-rotated-internal-alignment.svg
ac47bab71f229d8f1348f10a00972b0e *tests/figs/textbox-grob/rotation-around-fixed-point.svg
7cd33292d3bce2d48077d0ecc3b2a73e *tests/testthat.R
e1d4c0c7540aef60afbb54b54835aa55 *tests/testthat/Rplots.pdf
71a5a91ab68f327c93554e62dabb0af6 *tests/testthat/Rplots.pdf
f514b2d400b37fef7ed436fbdb47d1d2 *tests/testthat/test-cpp.R
a407aef718691f5b73125ae61bcffeee *tests/testthat/test-grid-constructors.R
67d02a9078f7f82db1af5ed8b2fc2962 *tests/testthat/test-grid-renderer.R
f0b68517b0513767dc1eeec8b0211211 *tests/testthat/test-null-box.R
75c2bfc19d05d0489d7c889c6b0080c2 *tests/testthat/test-raster-box.R
d7a122809ddab111394319374c15d4ed *tests/testthat/test-rect-box.R
7f34b456a0f39084c6ed47c8d296b03b *tests/testthat/test-richtext-grob.R
a7f55d29268ff0ae3404bb7dbe870797 *tests/testthat/test-richtext-grob.R
db72fa0f82e6c74c7cedc8ddb6ba9f4c *tests/testthat/test-text-details.R
aa8d6e3decfec890a8dff2e20e02c343 *tests/testthat/test-textbox-grob.R
b1312163a7d3624f60417f99ed3733c9 *tests/testthat/test-textbox-grob.R
499e255bd1e6bf22cfbfe465194a03a9 *tests/testthat/test-vbox.R
5 changes: 5 additions & 0 deletions NEWS.md
@@ -1,3 +1,8 @@
# gridtext 0.1.1

- `richtext_grob()` and `textbox_grob()` now gracefully handle empty strings
and NAs.

# gridtext 0.1.0

First public release. Provides the two grobs `richtext_grob()` and `textbox_grob()` for formatted text rendering without and with word wrapping, respectively.
4 changes: 3 additions & 1 deletion R/richtext-grob.R
Expand Up @@ -98,6 +98,8 @@ richtext_grob <- function(text, x = unit(0.5, "npc"), y = unit(0.5, "npc"),

# make sure we can handle input text even if provided as factor
text <- as.character(text)
# convert NAs to empty strings
text <- ifelse(is.na(text), "", text)

# make sure margin and padding are of length 4
margin <- rep(margin, length.out = 4)
Expand Down Expand Up @@ -222,7 +224,7 @@ make_inner_box <- function(text, halign, valign, use_markdown, gp) {
if (use_markdown) {
text <- markdown::markdownToHTML(text = text, options = c("use_xhtml", "fragment_only"))
}
doctree <- read_html(text)
doctree <- read_html(paste0("<!DOCTYPE html>", text))

drawing_context <- setup_context(gp = gp, halign = halign, word_wrap = FALSE)
boxlist <- process_tags(xml2::as_list(doctree)$html$body, drawing_context)
Expand Down
4 changes: 3 additions & 1 deletion R/textbox-grob.R
Expand Up @@ -172,6 +172,8 @@ textbox_grob <- function(text, x = NULL, y = NULL,

# make sure we can handle input text even if provided as factor
text <- as.character(text)
# convert NAs to empty strings
text <- ifelse(is.na(text), "", text)

# determine orientation and adjust accordingly
orientation <- match.arg(orientation)
Expand Down Expand Up @@ -236,7 +238,7 @@ textbox_grob <- function(text, x = NULL, y = NULL,
if (use_markdown) {
text <- markdown::markdownToHTML(text = text, options = c("use_xhtml", "fragment_only"))
}
doctree <- read_html(text)
doctree <- read_html(paste0("<!DOCTYPE html>", text))

# if width is set to NULL, we use the native size policy and turn off word wrap
if (is.null(width)) {
Expand Down
11 changes: 5 additions & 6 deletions README.md
Expand Up @@ -21,18 +21,17 @@ Improved text rendering support for grid graphics in R.

## Installation

To install the latest development version of this package, please run
the following line in your R console:
You can install the current release from CRAN with `install.packages()`:

``` r
remotes::install_github("wilkelab/gridtext")
install.packages("gridtext")
```

Once the package is available on CRAN, you will be able to install the
latest release via `install.packages()` as usual:
To install the latest development version of this package, please run
the following line in your R console:

``` r
install.packages("gridtext")
remotes::install_github("wilkelab/gridtext")
```

## Examples
Expand Down
16 changes: 5 additions & 11 deletions src/grid.cpp
@@ -1,21 +1,15 @@
#include "grid.h"

NumericVector unit_pt(NumericVector x) {
NumericVector out(x);
out.attr("class") = "unit";
out.attr("valid.unit") = IntegerVector(1, 8);
out.attr("unit") = "pt";

return out;
// create unit vector by calling back to R
Environment env = Environment::namespace_env("grid");
Function unit = env["unit"];
return unit(x, "pt");
}

NumericVector unit_pt(Length x) {
NumericVector out(1, x);
out.attr("class") = "unit";
out.attr("valid.unit") = IntegerVector(1, 8);
out.attr("unit") = "pt";

return out;
return unit_pt(out);
}

List gpar_empty() {
Expand Down
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/testthat/test-richtext-grob.R
Expand Up @@ -79,6 +79,15 @@ test_that("grobheight and grobwidth work", {
expect_equal(h1, h2)
})

test_that("misc. tests", {
# empty strings work
expect_silent(richtext_grob(""))
expect_silent(richtext_grob(" "))

# NAs work
expect_silent(richtext_grob(c(" ", "abc", NA)))
})

test_that("visual tests", {
draw_labels <- function() {
function() {
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-textbox-grob.R
@@ -1,5 +1,14 @@
context("textbox grob")

test_that("misc. tests", {
# empty strings work
expect_silent(textbox_grob(""))
expect_silent(textbox_grob(" "))

# NAs work
expect_silent(textbox_grob(NA))
})

test_that("visual tests", {
draw_box <- function() {
function() {
Expand Down

0 comments on commit 6c6d9d6

Please sign in to comment.