Skip to content
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

plumber fails to run when type is already defined in the global namespace #787

Closed
LTLA opened this issue Mar 25, 2021 · 0 comments · Fixed by #789
Closed

plumber fails to run when type is already defined in the global namespace #787

LTLA opened this issue Mar 25, 2021 · 0 comments · Fixed by #789
Milestone

Comments

@LTLA
Copy link

LTLA commented Mar 25, 2021

System details

Output of sessioninfo::session_info()():

─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.0.3 Patched (2021-01-08 r79815)
 os       macOS Catalina 10.15.5
 system   x86_64, darwin19.5.0
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Los_Angeles
 date     2021-03-25

─ Packages ───────────────────────────────────────────────────────────────────
 package     * version     date       lib source
 assertthat    0.2.1       2019-03-21 [1] CRAN (R 4.0.3)
 callr         3.5.1       2020-10-13 [1] CRAN (R 4.0.3)
 cli           2.3.0       2021-01-31 [1] CRAN (R 4.0.3)
 crayon        1.4.1       2021-02-08 [1] CRAN (R 4.0.3)
 curl          4.3         2019-12-02 [1] CRAN (R 4.0.3)
 glue          1.4.2       2020-08-27 [1] CRAN (R 4.0.3)
 jsonlite      1.7.2       2020-12-09 [1] CRAN (R 4.0.3)
 later         1.1.0.1     2020-06-05 [1] CRAN (R 4.0.3)
 lifecycle     1.0.0       2021-02-15 [1] CRAN (R 4.0.3)
 magrittr      2.0.1       2020-11-17 [1] CRAN (R 4.0.3)
 pkgbuild      1.2.0       2020-12-15 [1] CRAN (R 4.0.3)
 plumber     * 1.0.0.90002 2021-03-25 [1] Github (rstudio/plumber@28bc58c)
 prettyunits   1.1.1       2020-01-24 [1] CRAN (R 4.0.3)
 processx      3.4.5       2020-11-30 [1] CRAN (R 4.0.3)
 promises      1.2.0.1     2021-02-11 [1] CRAN (R 4.0.3)
 ps            1.5.0       2020-12-05 [1] CRAN (R 4.0.3)
 R6            2.5.0       2020-10-28 [1] CRAN (R 4.0.3)
 Rcpp          1.0.6       2021-01-15 [1] CRAN (R 4.0.3)
 remotes       2.2.0       2020-07-21 [1] CRAN (R 4.0.3)
 rlang         0.4.10      2020-12-30 [1] CRAN (R 4.0.3)
 rprojroot     2.0.2       2020-11-15 [1] CRAN (R 4.0.3)
 rstudioapi    0.13        2020-11-12 [1] CRAN (R 4.0.3)
 sessioninfo   1.1.1       2018-11-05 [1] CRAN (R 4.0.3)
 stringi       1.5.3       2020-09-09 [1] CRAN (R 4.0.3)
 swagger       3.33.1      2020-10-02 [1] CRAN (R 4.0.3)
 webutils      1.1         2020-04-28 [1] CRAN (R 4.0.3)
 withr         2.4.1       2021-01-26 [1] CRAN (R 4.0.3)

[1] /Users/luna/Software/R/R-4-0-branch/library

Example application or steps to reproduce the problem

The plumber script is as follows:

library(BiocGenerics)

#' @get /
#' @serializer html
function() {
    "YAY"
}

Running this gives me (omitting BiocGenerics start-up messages):

p <- plumber::plumb("plumber.R")
p$run()
## Running plumber API at http://127.0.0.1:7515
## Error in nchar(ctype) :
##   cannot coerce type 'closure' to vector of type 'character'

Describe the problem in detail

BiocGenerics defines a type() function that is inadvertently found by plumber::responsesSpecification at

plumber/R/openapi-spec.R

Lines 68 to 71 in 28bc58c

ctype <- tryCatch({
get("type", envir =
environment(get("serialize_fn", envir =
environment(endpts$serializer))))},

This is unlikely to be an issue with BiocGenerics, but rather, a general problem that would occur with any package that defines a type() function. In fact, the same error can be obtained after omitting the library(BiocGenerics) by doing:

type <- function(x) x
p <- plumber::plumb("plumber.R")
p$run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants