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

set parser failed with attempt to apply non-function #937

Open
jangorecki opened this issue Dec 1, 2023 · 0 comments
Open

set parser failed with attempt to apply non-function #937

jangorecki opened this issue Dec 1, 2023 · 0 comments

Comments

@jangorecki
Copy link

Using latest CRAN plumber. Consulted news file and my issue does not seem to be solved in devel.

System details

R version 4.3.2 (2023-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora Linux 39 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP;  LAPACK version 3.11.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Zurich
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] plumber_1.2.1   compiler_4.3.2  ellipsis_0.3.2  magrittr_2.0.3 
 [5] R6_2.5.1        cli_3.6.1       later_1.3.1     promises_1.2.1 
 [9] tools_4.3.2     swagger_3.33.1  Rcpp_1.0.11     stringi_1.8.1  
[13] jsonlite_1.8.7  webutils_1.2.0  httpuv_1.6.12   lifecycle_1.0.4
[17] rlang_1.1.2  

no {sessioninfo} pkg

Reproduce

create r.R file:

#* test
#* @post /test
function(x) {
  cat("input str(x):\n")
  cat(capture.output(str(x)), sep="\n")
  x
}

try setting parser

plumber::plumb("r.R")$setParser(list(json=list(simplifyMatrix=FALSE, simplifyDataFrame=FALSE), rds=list()))
#Error: attempt to apply non-function

Describe the problem in detail

Setting parser for json type to not simplify to matrix or data.frame is failing. Using according to manual of setParser method at https://www.rplumber.io/reference/Plumber.html?q=parser#method-setparsers-

Background

I need to set json parser because otherwise my API is not type stable (giving matrix or list depending on the length of vectors in the input), see without the parser:

plumber::plumb("r.R")$run(host="0.0.0.0", port=8000)
curl -H "Content-Type: application/json" --data '{"x":[[1,2,3], [4,5,6]]}' http://localhost:8000/test
curl -H "Content-Type: application/json" --data '{"x":[[1,2,3], [4,5]]}' http://localhost:8000/test
input str(x):
 int [1:2, 1:3] 1 4 2 5 3 6
input str(x):
List of 2
 $ : int [1:3] 1 2 3
 $ : int [1:2] 4 5
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

No branches or pull requests

1 participant