Edit dataTables

Entities that are dataTables require an attribute list. To edit a dataTable, first edit/create an attributeList and set the physical. Then create a new dataTable using the eml$dataTable() helper function as below:

dataTable <- eml$dataTable(entityName = "A descriptive name for the data (does not need to be the same as the data file)",
                 entityDescription = "A description of the data",
                 physical = physical,
                 attributeList = attributeList)

The dataTable must then be added to the EML. How exactly you do this will depend on whether there are dataTable elements in your EML, and how many there are. To replace whatever dataTable elements already exist, you could write:

doc$dataset$dataTable <- dataTable

If there is only one dataTable in your dataset, the EML package will usually “unpack” these, so that it is not contained within a list of length 1 - this means that to add a second dataTable, you cannot use the syntax doc$dataset$dataTable[[2]], since when unpacked this will contain the entityDescription as opposed to pointing to the second in a series of dataTable elements. Confusing - I know. Not to fear though - this syntax will get you on your way, should you be trying to add a second dataTable.

doc$dataset$dataTable <- list(doc$dataset$dataTable, dataTable)

If there is more than one dataTable in your dataset, you can return to the more straightforward construction of:

doc$dataset$dataTable[[i]] <- dataTable 

Where i is the index that you wish insert your dataTable into.

To add a list of dataTables to avoid the unpacking problem above you will need to create a list of dataTables

dts <- list() # create an empty list
for(i in seq_along(tables_you_need)){
  # your code modifying/creating the dataTable here
  dataTable <- eml$dataTable(entityName = dataTable$entityName,
                             entityDescription = dataTable$entityDescription,
                             physical = physical,
                             attributeList = attributeList)
  
  dts[[i]] <- dataTable # add to the list
}

After getting a list of dataTables, assign the resulting list to dataTable EML

doc$dataset$dataTable <- dts

By default, the online submission form adds all entities as otherEntity, even when most should probably be dataTable. You can use eml_otherEntity_to_dataTable to easily move items in otherEntity over to dataTable, and delete the old otherEntity.

Most tabular data or data that contain variables should be listed as a dataTable. Data that do not contain variables (eg: plain text readme files, pdfs, jpegs) should be listed as otherEntity.

eml_otherEntity_to_dataTable(doc, 
                             1, # Indexes of otherEntities you want to convert, for multiple use 1:5 or c(1,3,5..)
                             validate_eml = F) # set this to False if the physical or attributes are not added