ropensci / datapack

An R package to handle data packages
https://docs.ropensci.org/datapack
44 stars 9 forks source link

SystemMetadata() can't initialize if no <replicationPolicy> #52

Closed gothub closed 8 years ago

gothub commented 8 years ago

When a SystemMetadata object is initialized from a parsed sysmeta XML document, if that document doesn't contain a element, then the following error is produced as shown in the following example:

> library(datapack)
> library(httr)
> library(XML)
> response <- GET("https://gmn.lternet.edu/mn/v1/meta/doi:10.6073%2FAA%2Fknb-lter-hfr.145.3")
> xml <- xmlParse(content(response, as="text"))
No encoding supplied: defaulting to UTF-8.
> sysmeta <- SystemMetadata(xmlRoot(xml))

 Error in UseMethod("xmlAttrs", node) : 
  no applicable method for 'xmlAttrs' applied to an object of class "NULL" 
10 xmlAttrs(xml[["replicationPolicy"]]) at SystemMetadata.R#260
9 .local(x, ...) 
8 parseSystemMetadata(sm_obj, x) at SystemMetadata.R#202
7 parseSystemMetadata(sm_obj, x) at SystemMetadata.R#183
6 .local(...) 
5 .Method(...) 
4 eval(expr, envir, enclos) 
3 eval(.dotsCall, env) 
2 standardGeneric("SystemMetadata") at SystemMetadata.R#169
1 SystemMetadata(xmlRoot(xml)) 
> 
gothub commented 8 years ago

Fixed in commit e0a6a994d8b896b5f14bf13d1fad511f9e79dc64

ran devtools::check() - no problems encountered