eddelbuettel / rcpptoml

Rcpp Bindings to C++ parser for TOML files
GNU General Public License v2.0
36 stars 9 forks source link

Odd interaction with plumber #24

Closed schloerke closed 1 year ago

schloerke commented 6 years ago

Moving issue trestletech/plumber#293 over to rcpptoml

From original post:


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

# tmp.toml

[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:

# example.R

# 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

@hidjis and I found that RcppTOML::parseToml is behaving as if it's reading in a CRLF delimited file when the file is a LF file after a plumber router has been ran. If R is restarted, everything works as expected until the plumber router is $run().

There is no cpp code inside plumber.

Thank you for the help! -Barret

eddelbuettel commented 6 years ago

Hm. I am not really sure what you expect me to do here.

eddelbuettel commented 6 years ago

Could this be a Windows thing? I can re-read the TOML after I Ctrl-C out of plumber:

R> RcppTOML::parseToml("tmp.toml")
List of 1
 $ database:List of 2
  ..$ host: chr "0.0.0.0"
  ..$ user: chr "toto"
R>
R> plumber::plumb("example.R")$run()
Starting server to listen on port 8971
Running the swagger UI at http://127.0.0.1:8971/__swagger__/
^C

R> RcppTOML::parseToml("tmp.toml")
List of 1
 $ database:List of 2
  ..$ host: chr "0.0.0.0"
  ..$ user: chr "toto"
R>
schloerke commented 6 years ago

I believe it's a windows only problem. Could not reproduce on mac. Could reproduce on windows VM.

What I find odd is that the file is not being touched, but parseToml is interpreting the file with CRLF after plumber is closed in windows when the file does not contain CRLF line endings.

eddelbuettel commented 6 years ago

Agreed on both counts, and am as puzzled. I don't think the TOML parser does anything funky -- it just slurps a file. There should really be no side effects. Weird.

eddelbuettel commented 1 year ago

Closing as stale.