Code Monkey home page Code Monkey logo

Comments (6)

cboettig avatar cboettig commented on June 13, 2024

This issue to be addressed once we close #34 (e.g. can generate the class definitions).

from eml.

cboettig avatar cboettig commented on June 13, 2024

Among other things, I think that the S4 approach sidesteps our difficulties with the API construction.

For instance, currently we define eml_dataset struggles to list its arguments as the arguments to it's child nodes and then uses some ugly do.call and if statements to check if a child node is included

eml_dataset <- function(..., .title = "Unnamed", .creator=list(), .contact=list(), .methods=list(), .coverage=list(), .rights = eml$get("default_rights")){
  dataset <- newXMLNode("dataset")
  title <- newXMLNode("title", .title)
  rights <- newXMLNode("intellectualRights", .rights)
  addChildren(dataset, title)

  creator <- do.call(eml_person, c(person_type="creator", .contact))
  addChildren(dataset, creator)
  contact <- do.call(eml_person, c(person_type="contact", .creator)) 
  addChildren(dataset, contact)

  if(!is.empty(.coverage)){
   coverage <- do.call(eml_coverage, .coverage)
   addChildren(dataset, coverage)
  }

  ## Methods node
  methods_node <- newXMLNode("methods", parent=dataset)
  if(!is.empty(.methods)){
   methods_node <- 
     do.call(eml_methods, 
             c(node = methods_node,
               .methods))
  }
....

All of this is sidestepped when this creature is instead an S4 object with children defined in slots:

setClass('eml_dataset', 
         representation(title = "XMLInternalElementNode",
                        creator = "XMLInternalElementNode",
                        rights = "XMLInternalElementNode",
                        methods = "XMLInternalElementNode",
                        datatable = "XMLInternalElementNode"))

Which is easy to extend. (Of course we don't have to write it manually, and the abstract node type can be replaced with detailed node definitions as they are written / once they are generated). @duncantl What then would the arguments to the eml_write or eml_dataset functions look like (to maintain a clean API)? Can we just map/match arguments to S4 slots?

from eml.

duncantl avatar duncantl commented on June 13, 2024

The XMLSchema package generates the constructor functions for the classes corresponding to eml_dataset, eml_write, etc. Yes, they provide a map from arguments to slots. They also get the optional slots and default values correct when they are specified in the schema.

from eml.

duncantl avatar duncantl commented on June 13, 2024

Why would the slots of eml_dataset be XMLInternalElementNode? The goal is to map the XML from an eml document to regular R objects and similarly, to map the R objects to an XML document that can be exported.

from eml.

cboettig avatar cboettig commented on June 13, 2024

Right, that was just me being lazy in the example. I think I comment above
that they would actually be the node classes (eg from XMLschema)


Carl Boettiger
http://carlboettiger.info

sent from mobile device; my apologies for any terseness or typos
On Jul 25, 2013 5:10 PM, "Duncan Temple Lang" [email protected]
wrote:

Why would the slots of eml_dataset be XMLInternalElementNode? The goal is
to map the XML from an eml document to regular R objects and similarly, to
map the R objects to an XML document that can be exported.


Reply to this email directly or view it on GitHubhttps://github.com/ropensci/reml/issues/38#issuecomment-21593718
.

from eml.

cboettig avatar cboettig commented on June 13, 2024

Ah, so we will get the constructor fns automatically too; cool. Will have
to see what they look like...


Carl Boettiger
http://carlboettiger.info

sent from mobile device; my apologies for any terseness or typos
On Jul 25, 2013 4:49 PM, "Duncan Temple Lang" [email protected]
wrote:

The XMLSchema package generates the constructor functions for the classes
corresponding to eml_dataset, eml_write, etc. Yes, they provide a map from
arguments to slots. They also get the optional slots and default values
correct when they are specified in the schema.


Reply to this email directly or view it on GitHubhttps://github.com/ropensci/reml/issues/38#issuecomment-21592928
.

from eml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.