Skip to content

Commit

Permalink
Merge pull request #31 from dipterix/master
Browse files Browse the repository at this point in the history
Moved `rmarkdown` to Suggests and installs when missing
  • Loading branch information
dfsp-spirit authored Jul 19, 2023
2 parents b44e351 + 56c3abd commit 6cf9572
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: freesurferformats
Type: Package
Title: Read and Write 'FreeSurfer' Neuroimaging File Formats
Version: 0.1.17
Version: 0.1.17.9000
Authors@R: person("Tim", "Schäfer", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-3683-8070"))
Maintainer: Tim Schäfer <[email protected]>
Description: Provides functions to read and write neuroimaging data in various file formats, with a focus on 'FreeSurfer' <http://freesurfer.net/> formats. This includes, but is not limited to, the following file formats: 1) MGH/MGZ format files, which can contain multi-dimensional images or other data. Typically they contain time-series of three-dimensional brain scans acquired by magnetic resonance imaging (MRI). They can also contain vertex-wise measures of surface morphometry data. The MGH format is named after the Massachusetts General Hospital, and the MGZ format is a compressed version of the same format. 2) 'FreeSurfer' morphometry data files in binary 'curv' format. These contain vertex-wise surface measures, i.e., one scalar value for each vertex of a brain surface mesh. These are typically values like the cortical thickness or brain surface area at each vertex. 3) Annotation file format. This contains a brain surface parcellation derived from a cortical atlas. 4) Surface file format. Contains a brain surface mesh, given by a list of vertices and a list of faces.
Expand All @@ -10,14 +10,15 @@ Encoding: UTF-8
URL: https://github.com/dfsp-spirit/freesurferformats
BugReports: https://github.com/dfsp-spirit/freesurferformats/issues
Imports:
utils,
pkgfilecache (>= 0.1.1),
xml2,
rmarkdown
xml2
Suggests:
knitr,
rmarkdown,
testthat (>= 2.1.0),
oro.nifti (>= 0.9),
gifti (>= 0.7.5),
cifti (>= 0.4.5)
VignetteBuilder: knitr
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ importFrom(pkgfilecache,erase_file_cache)
importFrom(pkgfilecache,get_filepath)
importFrom(pkgfilecache,get_pkg_info)
importFrom(pkgfilecache,list_available)
importFrom(rmarkdown,pandoc_available)
importFrom(stats,dist)
importFrom(stats,na.omit)
importFrom(utils,read.table)
Expand Down
42 changes: 40 additions & 2 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,49 @@ fs.surface.to.tmesh3d <- function(surface) {
#'
#' @return logical, whether Pandoc is available.
#'
#' @importFrom rmarkdown pandoc_available
#'
#' @keywords internal
has_pandoc <- function() {
assert_package("rmarkdown")
return(rmarkdown::pandoc_available());
}


assert_package <- function(pkg) {

package_installed <- vapply(pkg, function(p) {
return( system.file(package = p) != "" )
}, FALSE)
if( all(package_installed) ) { return(invisible()) }
pkg <- pkg[!package_installed]

# the package is missing
cnd <- structure(list(message = sprintf("Package(s) %s missing. Please install first.", paste(sQuote(pkg), collapse = ", ")), call = NULL),
class = c("package_not_found_error", "simpleError", "error", "condition"))

# check if rlang has been installed, usually yes if people installs any rlib/posit packages
rlang_is_missing <- system.file(package = "rlang") == ""
pak_is_missing <- system.file(package = "pak") == ""

# if not interactive or rlang&pak are missing, per CRAN policy, stop
if(!interactive() || (rlang_is_missing && pak_is_missing)) {
stop(cnd)
}

if( !rlang_is_missing ) {
rlang <- asNamespace("rlang")
rlang$check_installed(pkg)
return(invisible())
}

# using pak
message(sprintf("Package(s) %s missing, install?", paste(sQuote(pkg), collapse = ", ")))
if (utils::menu(c("Yes", "No")) != 1) {
invokeRestart("abort", cnd)
}
pak <- asNamespace("pak")
pak$pkg_install(pkg, ask = FALSE)

return(invisible())

}

0 comments on commit 6cf9572

Please sign in to comment.