jeroenjanssens / raylibr

R package that wraps Raylib, a simple and easy-to-use library to enjoy videogames programming
https://jeroenjanssens.github.io/raylibr/
Other
32 stars 5 forks source link

Error when using vectorized functions when some arguments are singular #11

Closed jeroenjanssens closed 1 year ago

jeroenjanssens commented 1 year ago

For example, this code:

library(raylibr)

positions <- matrix(c(100, 100, 200, 200), 2, 2, byrow = TRUE)
sizes <- c(50, 50)
cols <- c("red", "blue")

init_window()

while (!window_should_close()) {
  begin_drawing()
  clear_background()
  draw_rectangle_v(positions, sizes, cols)
  end_drawing()
}

close_window()

Produces the error:

Error in if (lens[3] < max_len) color <- rep(unlist(list(color)), length.out = max_len) : 
  missing value where TRUE/FALSE needed

This is because nrow(size) returns NULL. As a result, the lens vector doesn't contain all the lengths. A temporary workaround until this gets fixed is to pass a matrix for size:

sizes <- matrix(c(50, 50, 50, 50), 2, 2, byrow = TRUE)

Which correctly produces:

Screenshot 2022-10-29 at 17 56 22