diff --git a/R/ZenodoRecord.R b/R/ZenodoRecord.R index 1c61136..182e188 100644 --- a/R/ZenodoRecord.R +++ b/R/ZenodoRecord.R @@ -751,38 +751,55 @@ ZenodoRecord <- R6Class("ZenodoRecord", return(removed) }, + #' @description Set subjects + #' @param subjects a vector or list of subjects to set for the record + setSubjects = function(subjects){ + if(is.null(self$metadata$subjects)) self$metadata$subjects <- list() + for(subject in subjects){ + self$addSubject(subject) + } + }, + #' @description Set keywords #' @param keywords a vector or list of keywords to set for the record setKeywords = function(keywords){ - if(is.null(self$metadata$keywords)) self$metadata$keywords <- list() - for(keyword in keywords){ - self$addKeyword(keyword) - } + warnMsg = "Method 'setKeywords' is deprecated, please use 'setSubjects'" + self$WARN(warnMsg) + self$setSubjects(keywords) }, - #' @description Add a keyword - #' @param keyword the keyword to add + #' @description Add a subject + #' @param subject the subject to add #' @return \code{TRUE} if added, \code{FALSE} otherwise - addKeyword = function(keyword){ + addSubject = function(subject){ added <- FALSE - if(is.null(self$metadata$keywords)) self$metadata$keywords <- list() - if(!(keyword %in% self$metadata$keywords)){ - self$metadata$keywords[[length(self$metadata$keywords)+1]] <- keyword + if(is.null(self$metadata$subjects)) self$metadata$subjects <- list() + if(!(subject %in% self$metadata$subjects)){ + self$metadata$subjects[[length(self$metadata$subjects)+1]] <- list(subject = subject) added <- TRUE } return(added) }, - #' @description Remove a keyword - #' @param keyword the keyword to remove + #' @description Add a keyword + #' @param keyword the keyword to add + #' @return \code{TRUE} if added, \code{FALSE} otherwise + addKeyword = function(keyword){ + warnMsg = "Method 'addKeyword' is deprecated, please use 'addSubject'" + self$WARN(warnMsg) + self$addSubject(keyword) + }, + + #' @description Remove a subject + #' @param subject the subject to remove #' @return \code{TRUE} if removed, \code{FALSE} otherwise - removeKeyword = function(keyword){ + removeSubject = function(subject){ removed <- FALSE - if(!is.null(self$metadata$keywords)){ - for(i in 1:length(self$metadata$keywords)){ - kwd <- self$metadata$keywords[[i]] - if(kwd == keyword){ - self$metadata$keywords[[i]] <- NULL + if(!is.null(self$metadata$subjects)){ + for(i in 1:length(self$metadata$subjects)){ + sbj <- self$metadata$subjects[[i]] + if(sbj$subject == subject){ + self$metadata$subjects[[i]] <- NULL removed <- TRUE break; } @@ -791,44 +808,11 @@ ZenodoRecord <- R6Class("ZenodoRecord", return(removed) }, - #' @description Adds a subject given a term and identifier - #' @param term subject term - #' @param identifier subject identifier - addSubject = function(term, identifier){ - subject <- list(term = term, identifier = identifier) - if(is.null(self$metadata$subjects)) self$metadata$subjects <- list() - self$metadata$subjects[[length(self$metadata$subjects)+1]] <- subject - }, - - #' @description Removes subject(s) by a property. The \code{by} parameter should be the name - #' of the subject property ('term' or 'identifier'). - #' @param by property used as criterion to remove subjects - #' @param property property value used to remove subjects - #' @return \code{TRUE} if at least one subject is removed, \code{FALSE} otherwise. - removeSubject = function(by, property){ - removed <- FALSE - for(i in 1:length(self$metadata$subjects)){ - subject <- self$metadata$subjects[[i]] - if(subject[[by]]==property){ - self$metadata$subjects[[i]] <- NULL - removed <- TRUE - } - } - return(removed) - }, - - #' @description Removes subject(s) by term. - #' @param term the term to use to remove subject(s) - #' @return \code{TRUE} if at least one subject is removed, \code{FALSE} otherwise. - removeSubjectByTerm = function(term){ - return(self$removeSubject(by = "term", property = term)) - }, - - #' @description Removes subject(s) by identifier - #' @param identifier the identifier to use to remove subject(s) - #' @return \code{TRUE} if at least one subject is removed, \code{FALSE} otherwise. - removeSubjectByIdentifier = function(identifier){ - return(self$removeSubject(by = "identifier", property = identifier)) + #' @description Remove a keyword + #' @param keyword the keyword to remove + #' @return \code{TRUE} if removed, \code{FALSE} otherwise + removeKeyword = function(keyword){ + self$removeSubject(keyword) }, #' @description Set notes. HTML is not allowed diff --git a/man/ZenodoRecord.Rd b/man/ZenodoRecord.Rd index f6e9a49..815f851 100644 --- a/man/ZenodoRecord.Rd +++ b/man/ZenodoRecord.Rd @@ -41,10 +41,6 @@ Emmanuel Blondel \item{\code{conceptrecid}}{record concept id} -\item{\code{doi}}{record doi} - -\item{\code{doi_url}}{record doi URL} - \item{\code{modified}}{record modification date} \item{\code{owners}}{record owners} @@ -65,8 +61,6 @@ Emmanuel Blondel \item{\code{links}}{list of links associated to the record} -\item{\code{media_files}}{media files} - \item{\code{metadata}}{metadata elements associated to the record} \item{\code{parent}}{parent record} @@ -127,13 +121,12 @@ Emmanuel Blondel \item \href{#method-ZenodoRecord-setReferences}{\code{ZenodoRecord$setReferences()}} \item \href{#method-ZenodoRecord-addReference}{\code{ZenodoRecord$addReference()}} \item \href{#method-ZenodoRecord-removeReference}{\code{ZenodoRecord$removeReference()}} +\item \href{#method-ZenodoRecord-setSubjects}{\code{ZenodoRecord$setSubjects()}} \item \href{#method-ZenodoRecord-setKeywords}{\code{ZenodoRecord$setKeywords()}} -\item \href{#method-ZenodoRecord-addKeyword}{\code{ZenodoRecord$addKeyword()}} -\item \href{#method-ZenodoRecord-removeKeyword}{\code{ZenodoRecord$removeKeyword()}} \item \href{#method-ZenodoRecord-addSubject}{\code{ZenodoRecord$addSubject()}} +\item \href{#method-ZenodoRecord-addKeyword}{\code{ZenodoRecord$addKeyword()}} \item \href{#method-ZenodoRecord-removeSubject}{\code{ZenodoRecord$removeSubject()}} -\item \href{#method-ZenodoRecord-removeSubjectByTerm}{\code{ZenodoRecord$removeSubjectByTerm()}} -\item \href{#method-ZenodoRecord-removeSubjectByIdentifier}{\code{ZenodoRecord$removeSubjectByIdentifier()}} +\item \href{#method-ZenodoRecord-removeKeyword}{\code{ZenodoRecord$removeKeyword()}} \item \href{#method-ZenodoRecord-setNotes}{\code{ZenodoRecord$setNotes()}} \item \href{#method-ZenodoRecord-setCommunities}{\code{ZenodoRecord$setCommunities()}} \item \href{#method-ZenodoRecord-addCommunity}{\code{ZenodoRecord$addCommunity()}} @@ -1190,142 +1183,117 @@ Remove a reference } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-setKeywords}{}}} -\subsection{Method \code{setKeywords()}}{ -Set keywords +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-setSubjects}{}}} +\subsection{Method \code{setSubjects()}}{ +Set subjects \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$setKeywords(keywords)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$setSubjects(subjects)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{keywords}}{a vector or list of keywords to set for the record} +\item{\code{subjects}}{a vector or list of subjects to set for the record} } \if{html}{\out{
}} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-addKeyword}{}}} -\subsection{Method \code{addKeyword()}}{ -Add a keyword -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$addKeyword(keyword)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{keyword}}{the keyword to add} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{TRUE} if added, \code{FALSE} otherwise -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-removeKeyword}{}}} -\subsection{Method \code{removeKeyword()}}{ -Remove a keyword +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-setKeywords}{}}} +\subsection{Method \code{setKeywords()}}{ +Set keywords \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$removeKeyword(keyword)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$setKeywords(keywords)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{keyword}}{the keyword to remove} +\item{\code{keywords}}{a vector or list of keywords to set for the record} } \if{html}{\out{
}} } -\subsection{Returns}{ -\code{TRUE} if removed, \code{FALSE} otherwise -} } \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZenodoRecord-addSubject}{}}} \subsection{Method \code{addSubject()}}{ -Adds a subject given a term and identifier +Add a subject \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$addSubject(term, identifier)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$addSubject(subject)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{term}}{subject term} - -\item{\code{identifier}}{subject identifier} +\item{\code{subject}}{the subject to add} } \if{html}{\out{
}} } +\subsection{Returns}{ +\code{TRUE} if added, \code{FALSE} otherwise +} } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-removeSubject}{}}} -\subsection{Method \code{removeSubject()}}{ -Removes subject(s) by a property. The \code{by} parameter should be the name - of the subject property ('term' or 'identifier'). +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-addKeyword}{}}} +\subsection{Method \code{addKeyword()}}{ +Add a keyword \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$removeSubject(by, property)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$addKeyword(keyword)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{by}}{property used as criterion to remove subjects} - -\item{\code{property}}{property value used to remove subjects} +\item{\code{keyword}}{the keyword to add} } \if{html}{\out{
}} } \subsection{Returns}{ -\code{TRUE} if at least one subject is removed, \code{FALSE} otherwise. +\code{TRUE} if added, \code{FALSE} otherwise } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-removeSubjectByTerm}{}}} -\subsection{Method \code{removeSubjectByTerm()}}{ -Removes subject(s) by term. +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-removeSubject}{}}} +\subsection{Method \code{removeSubject()}}{ +Remove a subject \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$removeSubjectByTerm(term)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$removeSubject(subject)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{term}}{the term to use to remove subject(s)} +\item{\code{subject}}{the subject to remove} } \if{html}{\out{
}} } \subsection{Returns}{ -\code{TRUE} if at least one subject is removed, \code{FALSE} otherwise. +\code{TRUE} if removed, \code{FALSE} otherwise } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-removeSubjectByIdentifier}{}}} -\subsection{Method \code{removeSubjectByIdentifier()}}{ -Removes subject(s) by identifier +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-removeKeyword}{}}} +\subsection{Method \code{removeKeyword()}}{ +Remove a keyword \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$removeSubjectByIdentifier(identifier)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$removeKeyword(keyword)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{identifier}}{the identifier to use to remove subject(s)} +\item{\code{keyword}}{the keyword to remove} } \if{html}{\out{
}} } \subsection{Returns}{ -\code{TRUE} if at least one subject is removed, \code{FALSE} otherwise. +\code{TRUE} if removed, \code{FALSE} otherwise } } \if{html}{\out{
}}