-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't assume all scripts are given as character variables. #321
Conversation
…ror message to only report missing files.
Thanks @dmurdoch! If you don't mind, it'd also be great to have a unit test |
Sure, I'll see if I can add one. |
The last commit adds a test. It just tries to see if the function runs without error; I think other tests check that the results are okay. |
R/html_dependency.R
Outdated
dependency[['attachment']]) | ||
if (anyUnnamed(file_list)) | ||
files <- vapply(file_list, | ||
function(f) if (is.list(f)) f[['src']] else f, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this correctly handle the case of htmlDependency("foo", "1.0", src="", script=list(list(src="file.js")))
? I think the tests should verify that the files were actually copied in order to verify this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's worth testing. I'll add that.
R/html_dependency.R
Outdated
file_list <- c(dependency[['script']], | ||
dependency[['stylesheet']], | ||
dependency[['attachment']]) | ||
if (anyUnnamed(file_list)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be clearer what's going on here if we were to have a helper function "pluck" the files from each slot first, then put them together. Something like
pluck_src <- function(x) {
if (is.character(x)) return(x)
if (is.list(x) && "src" %in% names(x)) return(x$src)
if (is.list(x)) return(pluck_src(x))
NULL
}
files <- c(
pluck_src(dep$script),
pluck_src(dep$stylesheet),
pluck_src(dep$attachment),
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function makes sense. I'll add that.
Co-authored-by: Carson Sievert <[email protected]>
Just committed changes as per suggestions. |
Just a note in case there are more comments: I'm going offline soon, and won't be available for a week or two. I'll address other comments when I get back. If they're urgently needed before that, someone else will have to take over. |
pluck_src <- function(x) { | ||
if (is.character(x)) return(x) | ||
if (is.list(x) && "src" %in% names(x)) return(x$src) | ||
if (is.list(x)) return(vapply(x, pluck_src, "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm finding it a bit challenging to understand what exactly this function is trying to do. I think it's in part because the shape of the data going in is pretty loose -- that's something that has long been a cause of issues when dealing with html dependency objects.
In this particular case, I'm wondering about the NULL
return and the vapply()
. If this vapply()
is called on the object and one of the items returns NULL
, that will result in an error. Will it ever get to the NULL
at the end of the function? If not, it would make sense to have it throw an error with a helpful message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just remembered that we actually have a spec for the HTML dependency data structure, in Shiny's TypeScript code. We can use this to reason about how this code should work.
https://github.com/rstudio/shiny/blob/474f1400/srcts/src/shiny/render.ts#L79-L128
I made some changes to the |
This would much simpler and easier to implement if the |
Also fixes the error message to only report missing files. Fixes #320.