#' @name write.tag
#' @title write.tag
#'
#' @description
#' This function exports a matrix to a *.tag file
#'
#' @usage
#' write.tag(mat, file)
#'
#' @param mat xy matrix with three columns (x, y, z) and the landmarks ordered by row
#'
#' @param file name of the tag file to save
#'
#' @return This function saves a *.tag file from a matrix
#'
#' @examples
#' # mat <- matrix(1:12), nrow = 4, ncol = 3)
#' # write.tag(mat, "my_matrix.tag")
#'
#' @author Marta Vidal-Garcia
#' @export
#'
write.tag <- function(mat, file){
mat_tag <- c()
for (i in 1:nrow(mat)){
if (i == nrow(mat)){
point <- paste0(" ", mat[i,1], " ", mat[i,2], " ", mat[i,3], " ", 1, " ",
1, " ", 1, " ", '"Marker";')
mat_tag <- append(mat_tag, point)
}
else {
point <- paste0(" ", mat[i,1], " ", mat[i,2], " ", mat[i,3], " ", 1, " ",
1, " ", 1, " ", '"Marker"')
mat_tag <- append(mat_tag, point)
}
}
file_tag <- c("MNI Tag Point File",
"Volumes = 1;",
paste0("% Volume 1 points converted with morpho.tools.GM::write.tag() ", "/", file),
"",
"Points =",
mat_tag)
writeLines(file_tag, file)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.