tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.06k stars 214 forks source link

Check filename early in render_highquality() call #233

Closed Pecners closed 1 year ago

Pecners commented 2 years ago

When filename is specified in the render_highquality() call, I think filename should be verified early in the call, and an error should be thrown if the filename is invalid. For instance, the path might be bad, or the user might be using glue::glue() or similar to produce the filename, and there could be an error there.

As it stands, if there is an error in the filename argument, render_highquality() will go through the whole process of rendering the image, which could take a long time, and then fail to save the image because there was a problem with the specified filename argument.

Thanks for all your work making this fabulous package a part of the R universe!

Reprex

library(rayshader)

small <- resize_matrix(montereybay, .25)

small %>% height_shade() %>% plot_3d(heightmap = small)

> This works

render_highquality(filename = "test.png")

> This fails after rendering because x doesn't exist

render_highquality(filename = paste0(x, "test.png"))

> Error in paste0(x, "test.png"): object 'x' not found

> This fails after rendering because the path is bad

render_highquality(filename = "bad/path/test.png")

> Error in png::writePNG(hillshade, filename): unable to create bad/path/test.png

sessioninfo::session_info()

Session info

> setting value

> version R version 4.1.2 (2021-11-01)

> os macOS Big Sur 10.16

> system x86_64, darwin17.0

> ui X11

> language (EN)

> collate en_US.UTF-8

> ctype en_US.UTF-8

> tz America/Chicago

> date 2022-06-09

> pandoc 2.14.0.3 @ /Applications/RStudio.app/Contents/MacOS/pandoc/ (via rmarkdown)

>

> ─ Packages

> package * version date (UTC) lib source

> cli 3.3.0 2022-04-25 [1] CRAN (R 4.1.2)

> codetools 0.2-18 2020-11-04 [1] CRAN (R 4.1.2)

> crayon 1.5.1 2022-03-26 [1] CRAN (R 4.1.2)

> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.2)

> doParallel 1.0.17 2022-02-07 [1] CRAN (R 4.1.2)

> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)

> evaluate 0.15 2022-02-18 [1] CRAN (R 4.1.2)

> extrafont 0.18 2022-04-12 [1] CRAN (R 4.1.2)

> extrafontdb 1.0 2012-06-11 [1] CRAN (R 4.1.0)

> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0)

> foreach 1.5.2 2022-02-02 [1] CRAN (R 4.1.2)

> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.0)

> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.2)

> highr 0.9 2021-04-16 [1] CRAN (R 4.1.0)

> hms 1.1.1 2021-09-26 [1] CRAN (R 4.1.0)

> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.0)

> htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.1.0)

> iterators 1.0.14 2022-02-05 [1] CRAN (R 4.1.2)

> jsonlite 1.8.0 2022-02-22 [1] CRAN (R 4.1.2)

> knitr 1.39 2022-04-26 [1] CRAN (R 4.1.2)

> lattice 0.20-45 2021-09-22 [1] CRAN (R 4.1.2)

> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0)

> magick 2.7.3 2021-08-18 [1] CRAN (R 4.1.0)

> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.1.2)

> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)

> png 0.1-7 2013-12-03 [1] CRAN (R 4.1.0)

> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0)

> progress 1.2.2 2019-05-16 [1] CRAN (R 4.1.0)

> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)

> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0)

> raster 3.5-15 2022-01-22 [1] CRAN (R 4.1.2)

> rayimage 0.6.5 2022-05-20 [1] Github (tylermorganwall/rayimage@4d671f1)

> rayrender 0.26.0 2022-05-20 [1] Github (tylermorganwall/rayrender@fd75c74)

> rayshader * 0.28.2 2022-05-20 [1] Github (tylermorganwall/rayshader@2b76c1b)

> Rcpp 1.0.8.3 2022-03-17 [1] CRAN (R 4.1.2)

> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0)

> rgdal 1.5-28 2021-12-15 [1] CRAN (R 4.1.0)

> rgl 0.108.3.2 2022-05-16 [1] CRAN (R 4.1.2)

> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.1.2)

> rmarkdown 2.14 2022-04-25 [1] CRAN (R 4.1.2)

> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)

> Rttf2pt1 1.3.10 2022-02-07 [1] CRAN (R 4.1.2)

> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.0)

> sp 1.4-7 2022-04-20 [1] CRAN (R 4.1.2)

> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.0)

> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)

> terra 1.5-21 2022-02-17 [1] CRAN (R 4.1.2)

> vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.1.2)

> withr 2.5.0 2022-03-03 [1] CRAN (R 4.1.2)

> xfun 0.31 2022-05-10 [1] CRAN (R 4.1.2)

> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.1.2)

>

> [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library

>

> ──────────────────────────────────────────────────────────────────────────────

AaqibGulzar commented 2 years ago

dear sir, i tried to follow the same steps of plotting a 3D visual of grand canyon as you put out in the blog but i am recieving this error after using render_highquality() function.Error in rayrender::render_scene(scene, lookfrom = lookfrom, lookat = camera_lookat, : unused argument (interactive = FALSE). please sir if you could help me with this.

Pecners commented 2 years ago

Your question is unrelated to this issue, but you could try two things:

  1. Make sure you're using the most up-to-date package versions for rayshader and rayrender -- the interactive argument is passed to rayrender::render_scene().
  2. Just remove interactive = FALSE
tylermorganwall commented 1 year ago

render_highquality() should validate the directory and filename before the render as of commit 5222e1e33492b9c5de7d0de31940d2f0dd9371c4.