davidcsterratt / RTriangle

Port of the Triangle Two-Dimensional Quality Mesh Generator and Delaunay Triangulator to R
https://cran.r-project.org/package=RTriangle
9 stars 4 forks source link

is.na(PB) throws warning when valid PB supplied #10

Open MilesMcBain opened 6 years ago

MilesMcBain commented 6 years ago

The issue that PB is a numeric vector, which is.na() is vectorised over. So if() sees a vector of FALSE which rightly throws a warning in newer versions of R.

Here's a Reprex:


library(tidyverse)
library(magrittr)

structure(list(

P = structure(c(2, 3, 3, 2, 1, 1, 0, 0, 0, 1,
2, 2, 3, 3, 2.25, 2.75, 2.75, 2.25, 0.25, 0.75, 0.75, 0.25, 0.25,
0.75, 0.75, 0.25, 1.1, 1.1, 2, 2, 1, 0, 0, 1, 2, 2, 0, 1, 1,
0, 1.25, 1.25, 1.75, 1.75, 0.25, 0.25, 0.75, 0.75, 1.25, 1.25,
1.75, 1.75), .Dim = c(26L, 2L), .Dimnames = list(NULL, c("x",
"y"))),

PB = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 

S = structure(c(1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 2L, 3L, 4L, 1L, 6L, 7L,
8L, 9L, 10L, 5L, 12L, 13L, 14L, 11L, 16L, 17L, 18L, 15L, 20L,
21L, 22L, 19L, 24L, 25L, 26L, 23L), .Dim = c(26L, 2L), .Dimnames = list(
NULL, c("segment_start", "segment_end"))), 

SB = c(1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0), 

H = structure(c(2.5, 0.5, 0.5, 1.5, 0.5, 1.5), .Dim = c(3L,
2L))), .Names = c("P", "PB", "S", "SB", "H")) %>%
do.call(RTriangle::pslg, .) %>%
RTriangle::triangulate() 
#> Warning in if (is.na(PB)) {: the condition has length > 1 and only the
#> first element will be used
davidcsterratt commented 5 years ago

Sorry for the delay replying to this. A patch along the lines you've suggested would be great, though it's now not merging, so I'd appreciate it if you could take another look. If it were possible to include the reproducible example as a test, that would be great too, but don't worry. Ideally it would not use the tidyverse & magrittr libraries.

davidcsterratt commented 5 years ago

Ah - hold that! I should look at the earlier NA-related patch first https://github.com/davidcsterratt/RTriangle/pull/9