bryanhanson / LindenmayeR

Lindenmayer or L-Systems in R
7 stars 1 forks source link

R CMD check failure with dev version of stringr #1

Closed hadley closed 9 years ago

hadley commented 9 years ago
checking dependencies in R code ... NOTE
Package in Depends field not imported from: ‘grid’
  These packages need to be imported from (in the NAMESPACE file)
  for when this namespace is loaded but not attached.
See the information on DESCRIPTION files in the chapter ‘Creating R
packages’ of the ‘Writing R Extensions’ manual.
checking R code for possible problems ... NOTE
drawLsys: no visible global function definition for ‘grid.newpage’
drawLsys: no visible global function definition for ‘viewport’
drawLsys: no visible global function definition for ‘pushViewport’
drawLsys: no visible global function definition for ‘grid.rect’
drawLsys: no visible global function definition for ‘grid.move.to’
drawLsys: no visible global function definition for ‘grid.line.to’
checking examples ... ERROR
Running examples in ‘LindenmayeR-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: drawLsys
> ### Title: Draw a 2D L-System Using Turtle Graphics
> ### Aliases: drawLsys
> ### Keywords: plot
> 
> ### ** Examples
> 
> require('grid')
> # Modified Koch curve
> rkoch1 <- data.frame(inp = c("F"), out = c("F+F-F-F+F"), stringsAsFactors = FALSE)
> k1 <- Lsys(init = "F", rules = rkoch1, n = 3)

Cycle 0 string has length 1
Cycle 0: F 

Cycle 1 string has length 9
Cycle 1: F+F-F-F+F

Cycle 2 string has length 49
Cycle 2: F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F

Cycle 3 string has length 249
Cycle 3: F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F+F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F+F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F
> dkoch <- data.frame(symbol = c("F", "f", "+", "-", "[", "]"),
+ action = c("F", "f", "+", "-", "[", "]"), stringsAsFactors = FALSE)
> drawLsys(string = k1, stepSize = 3, st = c(10, 50, 0), drules = dkoch)
> grid.text("Modified Koch Curve (n = 3)", 0.5, 0.25)
> 
> # Classic Koch snowflake
> rkoch2 <- data.frame(inp = c("F"), out = c("F-F++F-F"), stringsAsFactors = FALSE)
> k2 <- Lsys(init = "F++F++F", rules = rkoch2, n = 4)

Cycle 0 string has length 7
Cycle 0: F++F++F 

Cycle 1 string has length 28
Cycle 1: F-F++F-F++F-F++F-F++F-F++F-F

Cycle 2 string has length 112
Cycle 2: F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F

Cycle 3 string has length 448
Cycle 3: F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F

Cycle 4 string has length 1792
Cycle 4: F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F
> drawLsys(string = k2, stepSize = 1, ang = 60, st = c(10, 25, 0), drules = dkoch)
> grid.text("Classic Koch Snowflake (n = 4)", 0.5, 0.5)
> 
> # Sierpinski Triangle
> rSierp <- data.frame(inp = c("A", "B"), out = c("B-A-B", "A+B+A"), stringsAsFactors = FALSE)
> s <- Lsys(init = "A", rules = rSierp, n = 6)

Cycle 0 string has length 1
Cycle 0: A 
Error in Lsys(init = "A", rules = rSierp, n = 6) : 
  NAs are not allowed in subscripted assignments
Execution halted

Could you please explore? This may be an accident change in behaviour in stringr, or more consistent stringr code might have revealed a bug in your code.

The easiest way to fix the notes is to add import(grid) to your namespace. (Or prefix each call to a grid function with grid::)

bryanhanson commented 9 years ago

Thanks for the heads up Hadley. Problem is fixed in the 2D branch on Github. I will send to CRAN after you send the new stringr. Problem appears to have been, I think, that str_locate_all used to return an empty list if no matches were found, and the dev version returns NA. At least, that's what it looks like from here.

hadley commented 9 years ago

Oh that's definitely a bug. It should be returning an empty list - could you try making a minimal reprex somewhere please?

bryanhanson commented 9 years ago

Here is a MWE, but I cannot replicate the behavior. I went back several stringr versions and they all return NA if no match is found, so I'm a little lost. In Example 1, the code was checking for an empty list, because at one point that worked. LindenmayeR was just written back in August, so I can't figure it out. Maybe it will be clear to you. Bryan

rules <- data.frame(inp = c("A", "B"), out = c("B-A-B", "A+B+A"), stringsAsFactors = FALSE)
init <- "A"
RR <- vector("list") # save the rule output here

# Example 1.  This is the newer version, changed today, on branch 2D
for (i in 1:nrow(rules)) {
    rr <- str_locate_all(init, rules[i,1])
    if (is.na(rr[[1]][1,1])) {
        next # no match, skip and keep going
        }       
    RR[i] <- rr
    }

# Example 2.  Previous/Original version

for (i in 1:nrow(rules)) {
    rr <- str_locate_all(init, rules[i,1])
    if (dim(rr[[1]])[1] == 0) {
            next # no match, skip and keep going
            # This was a way of checking for an empty list
        }
    RR[i] <- rr
    }

# The 'correct' answer is 
# RR
# [[1]]
     # start end
# [1,]     1   1

# Old version of stringr (0.6.2) gives this answer for Example 1 and 2
# RR
# [[1]]
     # start end
# [1,]     1   1

# [[2]]
     # start end
# [1,]    NA  NA

Dev version (stringr_0.9.0.9000) gives the same answers! so do 0.6.1, 0.6. 0.5

hadley commented 9 years ago

Oops, I used FALSE in a couple of places where I should've used TRUE.Fixed now!

bryanhanson commented 9 years ago

So no match will return an empty list element? Thanks, Bryan

On Dec 10, 2014, at 5:16 PM, Hadley Wickham notifications@github.com wrote:

Oops, I used FALSE in a couple of places where I should've used TRUE.Fixed now!

— Reply to this email directly or view it on GitHub.

hadley commented 9 years ago

It returns a zero-row matrix - i.e. there's always one row per match