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

is the array behavior correct? #15

Closed
dpastoor opened this issue Mar 25, 2017 · 5 comments
Closed

is the array behavior correct? #15

dpastoor opened this issue Mar 25, 2017 · 5 comments

Comments

@dpastoor
Copy link
Contributor

@dpastoor dpastoor commented Mar 25, 2017

Hi Dirk,

Maybe I am reading the spec for TOML incorrectly, but using the following example:

## Array of Tables

# These can be expressed by using a table name in double brackets. Each table
# with the same double bracketed name will be an element in the array. The
# tables are inserted in the order encountered.

[[products]]

name = "Hammer"
sku = 738594937

[[products]]

[[products]]

name = "Nail"
sku = 284758393
color = "gray"

I would expect the resulting structure to be a list of lists

output <- list(products = list(
        list(name = "Hammer", sku = 738594937),
        list(), 
        list(name = "Nail", sku = 284758393, color = "gray")
       )
)

output$product # gives a list of lists

This seems consistent with the example given https://github.com/toml-lang/toml#user-content-array-of-tables

vs the current implementation, which gives

List of 3
 $ products:List of 2
  ..$ name: chr "Hammer"
  ..$ sku : int 738594937
 $ products: list()
 $ products:List of 3
  ..$ color: chr "gray"
  ..$ name : chr "Nail"
  ..$ sku  : int 284758393

which seems the equivalent of

output <- list(products = list(name = "Hammer", sku = 738594937),
      products = list(), 
      products = list(name = "Nail", sku = 284758393, color = "gray")
)

output$product # only gives the list of the first product

which makes it 'impossible' to query by name

@eddelbuettel
Copy link
Owner

@eddelbuettel eddelbuettel commented Mar 25, 2017

I think you have a valid point. When I pipe the input you show above into parse_stdin from the cpptoml repo, I get (and what what follows in hand-indented by me and Emacs):

{"products":
 [
     {"sku":{"type":"integer","value":"738594937"},
      "name":{"type":"string","value":"Hammer"}
     },
     {
     },
     {"sku":{"type":"integer","value":"284758393"},
      "color":{"type":"string","value":"gray"},
      "name":{"type":"string","value":"Nail"}
     }
 ]
}

Not sure I will have time to chase this though.

eddelbuettel added a commit that referenced this issue Mar 25, 2017
@eddelbuettel
Copy link
Owner

@eddelbuettel eddelbuettel commented Mar 25, 2017

Try the new branch I pushed:

edd@max:~/git/rcpptoml(bugfix/issue15)$ r -lRcppTOML -p -e'parseTOML("/tmp/devin.toml")'
List of 1
 $ products:Dotted pair list of 3
  ..$ :List of 2
  .. ..$ name: chr "Hammer"
  .. ..$ sku : int 738594937
  ..$ : list()
  ..$ :List of 3
  .. ..$ color: chr "gray"
  .. ..$ name : chr "Nail"
  .. ..$ sku  : int 284758393
edd@max:~/git/rcpptoml(bugfix/issue15)$ 
@dpastoor
Copy link
Contributor Author

@dpastoor dpastoor commented Mar 25, 2017

Winner winner!

Works perfectly for both the example and the internal code I was using when ran into the issue 👍

For later reference, session_info

Session info ----------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, mingw32             
 ui       RStudio (1.1.96)            
 language (EN)                        
 collate  English_United States.1252  
 tz       America/New_York            
 date     2017-03-25                  

Packages --------------------------------------------------------------------------------------------------
 package  * version date       source                                
 curl       2.3     2016-11-24 CRAN (R 3.3.2)                        
 devtools   1.12.0  2016-06-24 CRAN (R 3.3.2)                        
 digest     0.6.12  2017-01-27 CRAN (R 3.3.2)                        
 git2r      0.18.0  2017-01-01 CRAN (R 3.3.2)                        
 httr       1.2.1   2016-07-03 CRAN (R 3.3.2)                        
 memoise    1.0.0   2016-01-29 CRAN (R 3.3.2)                        
 R6         2.2.0   2016-10-05 CRAN (R 3.3.2)                        
 Rcpp       0.12.10 2017-03-19 CRAN (R 3.3.3)                        
 RcppTOML * 0.1.1.2 2017-03-25 Github (eddelbuettel/rcpptoml@df9846b)
 withr      1.0.2   2016-06-20 CRAN (R 3.3.2)                        
 yaml       2.1.14  2016-11-12 CRAN (R 3.3.2)        
@eddelbuettel
Copy link
Owner

@eddelbuettel eddelbuettel commented Mar 25, 2017

Great. That was by the way pretty close to the perfect bug report and you clearly showed what you were getting, what you were expecting and what you got.

Good work for a weekend afternoon 🥇

@dpastoor
Copy link
Contributor Author

@dpastoor dpastoor commented Mar 25, 2017

:-) always try to be a good OSS citizen. So far moving things away from yaml to toml has been A+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.