Repository navigation
fix(interpolate_package): Check path and improve error messages - #763
Conversation
| interpolate_file(path, ..., .envir = .envir) | ||
| check_string(path) | ||
|
|
||
| path_pkg <- system.file("prompts", path, package = package) |
There was a problem hiding this comment.
Oh, one bit of friction here is that pkgload shims system.file() in the global env and in the loaded package namespace, so interpolate_package() doesn't work with dev packages.
Where I've needed that, I've written an internal interpolate_package() that replicated ellmer's implementation. But it'd be nice if there were a way around this. (The Shiny team has a system_file() function in Winston's staticimports package, but maybe there's rlang helper I haven't encountered yet?)
There was a problem hiding this comment.
Yeah, I think it's probably worth testing if package is a dev package (i.e. implement the shim ourselves).
There was a problem hiding this comment.
Makes sense. I captured this discussion in issue #766
interpolate_package()docs to correctinst/promptspathpathis scalar ininterpolate_package()andinterpolate_file().Before
Before this PR,
interpolate_package()falis with an error aboutinvalid "nchars" argumentbecausesystem.file()returns""for a missing path andfile.size("")returnsNA.In Positron at least, you typically only see the
ncharspart, like thiswhich is confusing -- my first thought is usually that I've done something wrong with the template strings.
After