Learn R Programming

rddi

This developer-focused package provides R representations of DDI Codebook 2.5 elements to safely construct fully-validated XML while still being flexible. There are 351 elements in the codebook schema, and while it is the intention of the package to ultimately cover most (if not all) of these, rddi also provides safe node creation tools to quickly create missing elements of the schema.

Installation

Install the latest stable version from CRAN:

install.packages("rddi")

Install the development from this repository with:

# install.packages("devtools")
devtools::install_github("nyuglobalties/rddi")

Example

Building components is quick and simple:

library(rddi)
library(magrittr)

main_citation <- ddi_citation(ddi_titlStmt(ddi_titl("Study Title")))

ddi_codeBook(ddi_stdyDscr(main_citation)) %>%
  as_xml_string() %>%
  cat()
#> <?xml version="1.0" encoding="UTF-8"?>
#> <codeBook xmlns="ddi:codebook:2_5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://www.ddialliance.org/Specification/DDI-Codebook/2.5/XMLSchema/codebook.xsd">
#>   <stdyDscr>
#>     <citation>
#>       <titlStmt>
#>         <titl>Study Title</titl>
#>       </titlStmt>
#>     </citation>
#>   </stdyDscr>
#> </codeBook>

Assert expected or required elements:

tryCatch(
  ddi_codeBook(),
  error = function(e) {
    print(e$message)
  }
)
#> No children specified when some are required: [stdyDscr]

tryCatch(
  ddi_citation(ddi_titlStmt(ddi_titl("Oops")), ddi_dataDscr()),
  error = function(e) {
    print(e$message)
  }
)
#> 'dataDscr' is not an acceptable child element for citation.
#> These are the allowed children: [titlStmt, rspStmt, prodStmt, distStmt, serStmt, verStmt, biblCit, holdings, notes]

Validate your work against the DDI Codebook 2.5 schema:

ddi_codeBook(ddi_stdyDscr(main_citation)) %>%
  validate_codebook()
#> [1] TRUE
#> attr(,"errors")
#> character(0)

Copy Link

Version

Install

install.packages('rddi')

Monthly Downloads

198

Version

0.1.1

License

GPL-3

Maintainer

Daniel Woulfin

Last Published

October 17th, 2022

Functions in rddi (0.1.1)

ddi_anlysUnit

anlysUnit node
ddi_catgry

catgry, catgryGrp and their child nodes
as_ddi

Convert XML trees to DDI objects
as_xml

Get XML representation of ddi_node objects
as_xml_string

Shortcut to text representation of DDI XML
ddi_anlyInfo

anlyInfo and its child nodes
ddi_dataDscr

dataDscr and its children
ddi_dataFingerprint

dataFingerprint and its child nodes
ddi_controlledVocabUsed

controlledVocabUsed and its child nodes
ddi_dataItem

dataItem and its child nodes
ddi_dataColl

dataColl and its children
ddi_contact

contact node
ddi_cohort

cohort and its child nodes
ddi_dataAccs

dataAccs and its children
ddi_concept

concept node
ddi_dataSrc

dataSrc node
ddi_distStmt

ddi_distStmt and its children
ddi_fileDscr

fileDscr and its children
ddi_docSrc

docSrc and its child nodes
ddi_developmentActivity

developmentActivity and its child nodes
ddi_dimensns

dimensns, recDimnsn and their child nodes
ddi_derivation

derivation and its child nodes
ddi_exPostEvaluation

exPostEvaluation and its child nodes
ddi_dmns

dmns and its child nodes
ddi_docDscr

docDscr and its children
ddi_embargo

embargo node
ddi_fileStrc

fileStrc and its child nodes
ddi_frameUnit

frameUnit and its children
ddi_method

method and its child nodes
ddi_mrow

mrow and its child nodes
ddi_geoBndBox

geoBndBox and its child nodes
ddi_fileTxt

fileTxt and its children
ddi_labl

labl node
ddi_imputation

imputation node
ddi_polygon

polygon and its child nodes
ddi_prodStmt

prodStmt and its child nodes
ddi_notes

notes node
ddi_otherMat

otherMat and its children
ddi_nCubeGrp

nCubeGrp and its child nodes
ddi_nCube

nCube and its child nodes
ddi_locMap

locMap and its child nodes
ddi_location

location node
ddi_point

point and its child nodes
ddi_qualityStatement

qualityStatement and its child nodes
ddi_producer

producer node
ddi_security

security node
ddi_othrStdyMat

othrStdyMat and its child nodes
ddi_serStmt

serStmt and its child nodes
ddi_range

range node
ddi_qstn

qstn and its child nodes
ddi_resource

resource and its child nodes
ddi_respUnit

respUnit node
ddi_row

row and its child nodes
ddi_recGrp

recGrp and its child nodes
ddi_standardsCompliance

standardsCompliance and its child nodes
ddi_stdyDscr

stdyDscr and its children
ddi_srcOrig

srcOrig documentation
ddi_sampleFrame

sampleFrame and its children
ddi_rspStmt

rspStmt and its child nodes
ddi_standard

standard and its child nodes
ddi_stdyInfo

stdyInfo and its child nodes
ddi_targetSampleSize

targetSampleSize and its children nodes
ddi_tbody

tbody and its child nodes
ddi_table

table and its child nodes
ddi_sumDscr

sumDscr and its child nodes
ddi_studyAuthorization

studyAuthorization and its child nodes
ddi_var

var and its child nodes
ddi_valrng

valrng, invalrng, and their child nodes
ddi_usage

usage and its child nodes
ddi_useStmt

useStmt and its children
ddi_varGrp

varGrp and its child nodes
ddi_verStmt

verStmt and its child nodes
ddi_titl

titl node
ddi_titlStmt

titlStmt and its child nodes
validate_codebook

Validate generated codebook against DDI Codebook 2.5
ddi_tgroup

tgroup and its child nodes
ddi_thead

thead and its child nodes
ddi_universe

universe node
ddi_txt

txt node
ddi_setAvail

setAvail and its children
ddi_sources

sources and its child nodes
ddi_srcChar

srcChar node
ddi_srcDocu

srcDocu node
ddi_studyDevelopment

studyDevelopment and its child nodes
ddi_subject

subject and its child nodes
ddi_codeBook

Codebook
ddi_boundPoly

boundPoly and its child nodes
ddi_citation

citation, sourceCitation, fileCitation and their child nodes
ddi_codingInstructions

codingInstructions and its child nodes