Update an object

To update a data file associated with a data package, you need to do three things:

  1. update the object itself,
  2. update the resource map (which affiliates the object with the metadata), and
  3. update the metadata that describes that object

The datapack::replaceMember function takes care of the first two of these tasks. First you need to get the pid of the file you want to replace by using datapack::selectMember

# Select the EML PID
dataId <- selectMember(dp, name="sysmeta@formatId", value="text/csv")

Then use replaceMember:

# Replace the old file with the new
dp <- replaceMember(dp, dataId, replacement=file_path)

If you want to remove some files from the data package we can use datapack::removeMember. If we wanted to remove all the zip files associated with this data package, we can use datapack::removeMember:

zipId <- selectMember(dp, name="sysmeta@formatId", value="application/vnd.shp+zip")
removeMember(dp, zipId, removeRelationships = T)

You will need to be explicit about your format_id here based on the file type. A list of format IDs can be found here on the DataONE website. Use line 2 (Id:) exactly, character for character.

To accomplish the second task, you will need to update the metadata using the EML package. This is covered in Chapter 4. After you update a file, you will always need to update the metadata because parts of the physical section (such as the file size, checksum) will be different, and it may also require different attribute information.

Once you have updated your metadata and saved it, you can update the package itself.