rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.39k stars 256 forks source link

Plumber introduces errors in RcppTOML::parseTOML #293

Closed hidjis closed 6 years ago

hidjis commented 6 years ago

With a restarted console, I can parse the following TOML file (tmp.toml) with no errors:

[database]
host = "0.0.0.0"
user = "toto"
> RcppTOML::parseToml("tmp.toml")
List of 1
 $ database:List of 2
  ..$ host: chr "0.0.0.0"
  ..$ user: chr "toto"

Then, I can start plumber with the following simple example:

# plumber.R

#* Echo back the input
#* @param msg The message to echo
#* @get /echo
function(msg=""){
  list(msg = paste0("The message is: '", msg, "'"))
}
> plumber::plumb("example.R")$run()
Starting server to listen on port 6639
Running the swagger UI at http://127.0.0.1:6639/__swagger__/

But, if I stop the API, and try to parse again the toml file, I get the following error:

> RcppTOML::parseToml("tmp.toml")
Error in tomlparseImpl(path.expand(input), verbose, fromFile) : 
'---did you forget a '#'? at line 1

Any idea, why it's causing an error after calling plumber ? It looks like plumber is loading RcppTOML and changing its behavior.

This is my sessionInfo at the beginning:

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

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

loaded via a namespace (and not attached):
[1] compiler_3.4.4 tools_3.4.4    yaml_2.2.0  

And at the end.

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

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

loaded via a namespace (and not attached):
 [1] plumber_0.4.6  compiler_3.4.4 magrittr_1.5   R6_2.2.2       RcppTOML_0.1.3 promises_1.0.1
 [7] later_0.7.3    tools_3.4.4    rstudioapi_0.7 yaml_2.2.0     crayon_1.3.4   Rcpp_0.12.18  
[13] stringi_1.1.7  jsonlite_1.5   httpuv_1.4.5

files.zip

schloerke commented 6 years ago

This issue is not related with plumber. It is isolated to RcppTOML.

Thank you for the files. I was able to reproduce your error without loading RcppTOML. RcppTOML has issues loading files that are saved with CRLF line endings. It worked fine for my when I changed them back to LF line endings.

# save lf file
cat('[database]\nhost = "0.0.0.0"\nuser = "toto"', file = "test_lf.toml")
# save crlf file
cat('[database]\r\nhost = "0.0.0.0"\r\nuser = "toto"', file = "test_crlf.toml")

RcppTOML::parseToml("test_lf.toml")
#> List of 1
#>  $ database:List of 2
#>   ..$ host: chr "0.0.0.0"
#>   ..$ user: chr "toto"
RcppTOML::parseToml("test_crlf.toml")
#> Error in tomlparseImpl(path.expand(input), verbose, fromFile): Unidentified trailing character '
'---did you forget a '#'? at line 1

Created on 2018-08-14 by the reprex package (v0.2.0).

hidjis commented 6 years ago

Thank you for your prompt response.

Just out of curiosity, do you have an explanation on why the result of RcppTOML::parseToml changes after using plumber. I used the test_lf.toml and I still get an error only after calling plumber.

> # save lf file
> cat('[database]\nhost = "0.0.0.0"\nuser = "toto"', file = "test_lf.toml")
> # call RcppTOML the first time before plumber
> RcppTOML::parseToml("test_lf.toml")
List of 1
 $ database:List of 2
  ..$ host: chr "0.0.0.0"
  ..$ user: chr "toto"
> # call plumber
> plumber::plumb("example.R")$run()
Starting server to listen on port 5389
Running the swagger UI at http://127.0.0.1:5389/__swagger__/

> # call RcppTOML the second time after plumber
> RcppTOML::parseToml("test_lf.toml")
Error in tomlparseImpl(path.expand(input), verbose, fromFile) : 
'---did you forget a '#'? at line 1

This behavior happened only on windows. In linux, I can parse test_lf with no errors before and after calling plumber.

schloerke commented 6 years ago

Sorry, I do not know.

I can reproduce your error. The tmp.toml file is not touched in any way. If you restart R after achieving the error, the error goes away until run the server object.

Since there is no Rcpp code in plumber, I'm going to redirect this issue to the RcppTOML repo.

hidjis commented 6 years ago

Thank you for your reply and the time you devoted on this issue.