Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix set_project bug #173

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions EMLeditor.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 25a099de-8eb3-4bb2-b366-f37bd0bee343

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# EMLeditor v0.1.7 (under development)
## 2025-01-16
* Fix bug in `set_project` and update associated documentation.
## 2024-11-04
* Fix documentation in EMLscript code chunk that can make it difficult/confusing to enter user input after running the `upload_data_package` function.
## 2024-10-23
Expand Down
63 changes: 40 additions & 23 deletions R/editEMLfunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1499,9 +1499,9 @@ set_protocol <- function(eml_object,
#' Adds a reference to a DataStore Project housing the data package
#'
#' @description
#' The function will add a single project title and URL to the metadata corresponding to the DataStore Project reference that the data package should be linked to. Upon EML extraction on DataStore, the data package will automatically be added/linked to the DataStore project indicated.
#' The function will add a single project title and URL to the metadata corresponding to the DataStore Project reference that the data package should be linked to. Upon EML extraction on DataStore, the data package will automatically be added/linked to the DataStore project indicated.EML2.2.0 only supports a single project so `set_project()`will overwrite/replace an existing project element.
#'
#' @details This function will only add a project; it will not overwrite existing projects. To add a DataStore project to your metadata, the project must be publicly available. If you add multiple DataStore projects to metadata, only the first DataStore project will be used by DataStore. The person uploading and extracting the EML must be an owner on both the data package and project references in order to have the correct permissions for DataStore to create the desired link. If you have set NPS = TRUE and force = FALSE (the default settings), the function will also test whether you have owner-level permissions for the project which is necessary for DataStore to automatically connect your data package with the project.
#' @details This function will overwrite existing projects. To add a DataStore project to your metadata, the project must be publicly available. The person uploading and extracting the EML must be an owner on both the data package and project references in order to have the correct permissions for DataStore to create the desired link. If you have set NPS = TRUE and force = FALSE (the default settings), the function will also test whether you have owner-level permissions for the project which is necessary for DataStore to automatically connect your data package with the project.
#'
#' DataStore only add links between data packages and projects. DataStore cannot not remove data packages from projects. If need to remove a link between a data package and a project (perhaps you supplied the incorrect project reference ID at first), you will need to manually remove the connection using the DataStore web interface.
#'
Expand Down Expand Up @@ -1644,23 +1644,48 @@ set_project <- function(eml_object,
), id = "DataStore_project"
)

#whenever EML 3.0.0 comes out (or mutliple projects are allowd) this can
#be uncommented to allow set_project to add to existing projects
#rather than replace them:

#get existing projects:
existing_projects <- eml_object$dataset$project

if (is.null(existing_projects)) {
eml_object$dataset$project <- proj
} else {
#if there are multiple projects:
if (length(seq_along(existing_projects[[1]])) > 1) {
# combine new and old projects (with new DataStore project at the top)
proj <- append(list(proj), existing_projects)
# overwrite the existing projects in EML with new project list:
eml_object$dataset$project <- proj
if (force == FALSE) {
msg1 <- paste0("The DataStore project {.var {project_reference_id}} with",
" the title {.var {project_title}} has been added to your",
" metadata.")
msg2 <- paste0("Your data package will be automatically linked to this ",
"project when once it is uploaded to DataStore and the ",
"metadata are extracted.")
cli::cli_inform(c("i" = msg1))
cli::cli_inform(c("i" = msg2))
}
#if there is only one existing project:
if (length(seq_along(existing_projects[[1]])) == 1) {
proj <- append(list(proj), list(existing_projects))
eml_object$dataset$project <- proj
} else {
if (!is.null(existing_projects)) {
cli::cli_alert_info("This metadata already contains a Project")
cli::cli_inform("Are you sure you want to replace the existing project?")
var1 <- .get_user_input() #1: Yes; 2: No\n"
if (var1 == 1) {
eml_object$dataset$project <- proj
if (force == FALSE) {
msg1 <- paste0("The DataStore project {.var {project_reference_id}} ",
"with the title {.var {project_title}} has been added ",
"to your metadata.")
msg2 <- paste0("Your data package will be automatically linked to ",
"this project when once it is uploaded to DataStore ",
"and the metadata are extracted.")
cli::cli_inform(c("i" = msg1))
cli::cli_inform(c("i" = msg2))
}
}
if (var1 == 2) {
if (force == FALSE) {
cli::cli_inform("Your original project was retained.")
}
}
}
}

Expand All @@ -1671,16 +1696,7 @@ set_project <- function(eml_object,
# add/update EMLeditor and version to metadata:
eml_object <- .set_version(eml_object)

if (force == FALSE) {
msg1 <- paste0("The DataStore project {.var {project_reference_id}} with ",
"the title {.var {project_title}} has been added to your ",
"metadata.")
msg2 <- paste0("Your data package will be automatically linked to this ",
"project when once it is uploaded to DataStore and the ",
"metadata are extracted.")
cli::cli_inform(c("i" = msg1))
cli::cli_inform(c("i" = msg2))
}

return(eml_object)
}

Expand Down Expand Up @@ -2885,3 +2901,4 @@ set_missing_data <- function(eml_object,
}



4 changes: 2 additions & 2 deletions docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pandoc: 3.1.11
pandoc: '3.2'
pkgdown: 2.1.0
pkgdown_sha: ~
articles:
Expand All @@ -7,4 +7,4 @@ articles:
a03_Template_edits: a03_Template_edits.html
a04_Editing_fixing_eml: a04_Editing_fixing_eml.html
a05_advanced_functionality: a05_advanced_functionality.html
last_built: 2024-11-04T20:37Z
last_built: 2025-01-16T20:14Z
6 changes: 3 additions & 3 deletions docs/reference/set_project.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/set_project.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading