diff --git a/R/cmtk_io.R b/R/cmtk_io.R index 74074996..c7949987 100644 --- a/R/cmtk_io.R +++ b/R/cmtk_io.R @@ -154,9 +154,9 @@ read.cmtk<-function(con, CheckLabel=TRUE){ } #' Write out CMTK registration list to folder -#' +#' #' @details Note that transformation in the forward direction (i.e. sample->ref) -#' e.g. as calculated from a set of landmarks where set 1 is the sample is +#' e.g. as calculated from a set of landmarks where set 1 is the sample is #' considered an inverse transformation by the IGS software. So in order to #' use such a transformation as an initial affine with the registration #' command the switch --initial-inverse must be used specifying the folder @@ -168,11 +168,16 @@ read.cmtk<-function(con, CheckLabel=TRUE){ #' by default. #' @param reglist List specifying CMTK registration parameters #' @param foldername Path to registration folder (usually ending in .list) -#' @param version CMTK version for registration (default 2.4) +#' @param version CMTK version for registration (default 2.4). Will be converted +#' to character vector if not already. #' @export #' @family cmtk-io -write.cmtkreg<-function(reglist, foldername, version="2.4"){ - if(!is.null(attr(reglist, 'version')) && (attr(reglist, 'version') != version)) warning("Specified version (", version, ") is not the same as the version stored in the reglist object (", attr(reglist, 'version'), ").") +write.cmtkreg<-function(reglist, foldername, version="2.4") { + if(!is.character(version)) + version=as.character(version) + if(!is.null(attr(reglist, 'version')) && (attr(reglist, 'version') != version)) + warning("Specified version (", version, ") is not the same as the version stored in the reglist object (", attr(reglist, 'version'), ").") + dir.create(foldername, showWarnings=FALSE, recursive=TRUE) if(!is.list(reglist)) reglist=cmtkreglist(reglist) write.cmtk(reglist,file.path(foldername, "registration"), diff --git a/man/write.cmtkreg.Rd b/man/write.cmtkreg.Rd index 3851e896..97e7e31e 100644 --- a/man/write.cmtkreg.Rd +++ b/man/write.cmtkreg.Rd @@ -11,14 +11,15 @@ write.cmtkreg(reglist, foldername, version = "2.4") \item{foldername}{Path to registration folder (usually ending in .list)} -\item{version}{CMTK version for registration (default 2.4)} +\item{version}{CMTK version for registration (default 2.4). Will be converted +to character vector if not already.} } \description{ Write out CMTK registration list to folder } \details{ Note that transformation in the forward direction (i.e. sample->ref) - e.g. as calculated from a set of landmarks where set 1 is the sample is + e.g. as calculated from a set of landmarks where set 1 is the sample is considered an inverse transformation by the IGS software. So in order to use such a transformation as an initial affine with the registration command the switch --initial-inverse must be used specifying the folder diff --git a/tests/testthat/test-cmtk_io.R b/tests/testthat/test-cmtk_io.R index 64250b70..a88a2196 100644 --- a/tests/testthat/test-cmtk_io.R +++ b/tests/testthat/test-cmtk_io.R @@ -19,7 +19,7 @@ test_that("read.cmtk and write.cmtk can round-trip a registration file", { reglist=read.cmtkreg(reg) tf=tempfile('dofv1.1wshears_copy',fileext='.list') on.exit(unlink(tf,recursive=TRUE)) - write.cmtkreg(reglist,foldername=tf,version=1.1) + write.cmtkreg(reglist, foldername=tf, version=1.1) ctf=cmtkreg(tf,returnDir=TRUE) # equivalent because we are not interested in the file.info attributes # though this also removes version attribute which might be worth a thought