Skip to content
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
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ tmp/
revdep/
^codemeta\.json$
^tic.R$
^.pre-commit-config.yaml$
^.pre-commit-config.yaml$
^.*\.Rproj$
^\.Rproj\.user$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ revdep/
README.html
README_files/
figure/
.Rproj.user
*.Rproj

cit*.t*xt
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ VignetteBuilder:
knitr
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.99.9001
RoxygenNote: 7.0.0
X-schema.org-isPartOf: https://ropensci.org
X-schema.org-keywords: metadata, ropensci, phylogenetics,
independant-contrasts, biodiversity
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(`[`,otl_ott_id)
S3method("[",otl_ott_id)
S3method(candidate_for_synth,study_meta)
S3method(flags,match_names)
S3method(flags,taxon_info)
Expand Down Expand Up @@ -63,6 +63,7 @@ S3method(unique_name,tol_summary)
S3method(update,match_names)
export(candidate_for_synth)
export(flags)
export(get_citations)
export(get_publication)
export(get_study)
export(get_study_meta)
Expand Down
16 changes: 16 additions & 0 deletions R/base.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,19 @@ check_label_format <- function(x) {
return(FALSE)
}
}

# res is an output from .tol_induced_subtree or .tol_subtree
# returns a list with tree and study ids supporting a subtree
studies_from_otl <- function(res){
if (is.list(res)) {
if (!is.null(res$supporting_studies)) {
studies <- res$supporting_studies
}
else {
stop("Cannot find supporting studies")
}
}
study_ids <- sapply(stringr::str_split(studies, "@"), '[', 1)
trees <- sapply(stringr::str_split(studies, "@"), '[', 2)
return(list(study_ids = study_ids, trees = trees))
}
8 changes: 8 additions & 0 deletions R/studies-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ candidate_for_synth.study_meta <- function(sm) {
get_study_year.study_meta <- function(sm) {
sm[["nexml"]][["^ot:studyYear"]]
}

##' Get citations for a set of study ids
##' @export
##' @param study_ids is a vector of study ids
get_citations <- function(study_ids){
citations <- sapply(study_ids, function(x) get_publication.study_meta(get_study_meta(study_id = x)))
return(citations)
}
21 changes: 20 additions & 1 deletion R/tol.R
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ tol_subtree <- function(ott_id = NULL, node_id = NULL, label_format = NULL,
##' (the default).
##' @param file If specified, the function will write the subtree to a file in
##' newick format.
##' @param file_citations If specified, the function will write citations from
##' supporting source trees to a txt file. It will automatically add the "txt" extension.
##' @param ... additional arguments to customize the API call (see
##' \code{\link{rotl}} for more information).
##'
Expand Down Expand Up @@ -455,11 +457,28 @@ tol_subtree <- function(ott_id = NULL, node_id = NULL, label_format = NULL,
##' }
##' @export
tol_induced_subtree <- function(ott_ids = NULL, node_ids = NULL, label_format = NULL,
file, ...) {
file, file_citations, ...) {
res <- .tol_induced_subtree(
ott_ids = ott_ids, node_ids = node_ids,
label_format = label_format, ...
)
# print citations
if (!missing(file_citations)) {
filecit <- paste0(file_citations, ".txt")
citations <- get_citations(studies_from_otl(res)$study_ids)
unlink(filecit)
cat(paste(citations, collapse = '\n\n'), file = filecit)
message(paste0("Citations were written to ", filecit, " in dir ", getwd()))
}
# else {
# # enhance: if file is not provided write to tmp dir
# # tmpdir <- "temporary file dir"
# # message(paste("'citations.txt' file has been written to dir", tmpdir))
# filecit <- "citations.txt"
# enhance: print to screen at leats part of citations, so users know that they're there.
# }


if (!missing(file)) {
unlink(file)
cat(res$newick, file = file)
Expand Down
14 changes: 14 additions & 0 deletions man/get_citations.Rd

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

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

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

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

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

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

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

4 changes: 4 additions & 0 deletions man/tol_induced_subtree.Rd

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

10 changes: 5 additions & 5 deletions man/tol_node_info.Rd

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