feat: random_image_ext() — Lorem Picsum images for Shiny prototyping (closes #8)#17
Open
VincentGuyader wants to merge 2 commits into
Open
feat: random_image_ext() — Lorem Picsum images for Shiny prototyping (closes #8)#17VincentGuyader wants to merge 2 commits into
VincentGuyader wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new random_image_ext() helper to generate an htmltools <img> tag whose src points at the Lorem Picsum API, intended for quick Shiny UI prototyping.
Changes:
- Introduces
random_image_ext(width, height, seed)with input validation and URL-encoding forseed. - Adds test coverage for URL construction and argument validation.
- Wires the feature into the package exports/docs and adds
htmltoolstoImports.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
R/random_image_ext.R |
New implementation of random_image_ext() building a Picsum URL and returning an htmltools::img() tag. |
tests/testthat/test-image-ext.R |
New tests validating return type, URL formatting, seed encoding, and argument validation. |
NAMESPACE |
Exports random_image_ext() and imports htmltools::img, attempt::stop_if_not, utils::URLencode. |
DESCRIPTION |
Adds htmltools to Imports and updates RoxygenNote. |
man/random_image_ext.Rd |
Generated documentation for the new function. |
NEWS.md |
Changelog entry for random_image_ext(). |
man/shinipsum-package.Rd |
Minor package documentation formatting adjustment. |
Files not reviewed (2)
- man/random_image_ext.Rd: Language not supported
- man/shinipsum-package.Rd: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+26
to
+27
| is.numeric(.x) && length(.x) == 1L && !is.na(.x) && | ||
| .x >= 1L && .x == as.integer(.x) |
| } else { | ||
| stop_if_not( | ||
| seed, | ||
| ~ length(.x) == 1L && !is.na(.x), |
Comment on lines
+28
to
+43
| test_that("width / height are validated", { | ||
| expect_error(random_image_ext(width = 0), "width") | ||
| expect_error(random_image_ext(width = -10), "width") | ||
| expect_error(random_image_ext(width = 1.5), "width") | ||
| expect_error(random_image_ext(width = c(100, 200)), "width") | ||
| expect_error(random_image_ext(width = NA), "width") | ||
| expect_error(random_image_ext(width = "100"), "width") | ||
| expect_error(random_image_ext(height = 0), "height") | ||
| expect_error(random_image_ext(height = "x"), "height") | ||
| }) | ||
|
|
||
| test_that("seed is validated", { | ||
| expect_error(random_image_ext(seed = c("a", "b")), "seed") | ||
| expect_error(random_image_ext(seed = NA), "seed") | ||
| expect_error(random_image_ext(seed = character(0)), "seed") | ||
| # numeric / other atomic scalars are coerced to character |
Reworked from PR #8: drop the glue dependency (use sprintf), validate width/height/seed, URL-encode the seed, document that no network request is made, add a full test suite. htmltools added to Imports (used by htmltools::img); utils import is now actually used (URLencode). TDD: tests/testthat/test-image-ext.R written first (red), then implementation. Co-authored-by: feddelegrand7 <ihaddaden.fodeil@gmail.com>
e6a5fa5 to
9cee2c3
Compare
- valid_dim() predicate is now total (is.finite + round, never NA/error): Inf / NaN / 1e400 / complex / logical fail with the friendly message - seed predicate gains an is.atomic() guard so list()/non-atomic inputs fail cleanly instead of throwing - format dimensions with %.0f (no as.integer overflow to NA) - add tests for the tricky inputs above Co-authored-by: feddelegrand7 <ihaddaden.fodeil@gmail.com>
Member
Author
|
Thanks @copilot — all 3 points addressed in fa86cdd:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reworks @feddelegrand7's PR #8 into a mergeable state (the original branch is 5 years stale and had no tests).
What it does
random_image_ext(width = 400, height = 400, seed = NULL)returns an<img>htmltoolstag whosesrcpoints at the Lorem Picsum API:No network request is performed by the function itself — only the URL is built; the browser fetches the image. Drop it straight into a Shiny UI.
Changes vs PR #8
gluedependency — plainsprintf().width/heightmust be single positive integers;seedmust be a single non-missing scalar (coerced to character).seedis URL-encoded (utils::URLencode(reserved = TRUE)), so spaces / slashes don't break the URL.@examplesno longer hit the network in a way that bothersR CMD check(the call only builds a tag).tests/testthat/test-image-ext.R(return type, dimensions in URL, seeded URL + encoding, validation of every argument). Written first (red), then the implementation.htmltoolsadded toImports(used byhtmltools::img); the previously-unusedutilsimport is now actually used (URLencode).Test plan
devtools::test(): 3170 PASS / 0 FAIL (the single pre-existing WARN is thegeom_line(size=)deprecation onmaster, addressed by fix: 3 shinipsum issues — geom_line(size=) deprecation (#13), random_image args (#9), n_bars (#5) #15 / feat: random_ggplot('ts'), random_mock(), random_text(var=) — issues #4 #1 #3 #16, untouched here).R CMD check --no-manual: Status: OK (0 error / 0 warning / 0 note).R/random_image_ext.Rat 100% coverage.Note for the merge
Touches
DESCRIPTION(addshtmltoolsto Imports) like #15 / #16 — trivial conflict if those land first. Independent of everything else otherwise.Closes #8