#' Print method for an object of class \code{personfiles}.
#' @description
#' This function is the print method for an object of class \code{personfiles}.
#' @details
#' Set \code{name = "all"} to print all saved person files.
#' @param x
#' An object of class \code{personfiles}.
#' @param name
#' The person's name.
#' @param ...
#' Ignored.
#' @return
#' Returns invisibly the input \code{x}.
print.personfiles <- function(x, name = "all", ...) {
if(!is_personfiles(x))
stop("Not of class 'personfiles'.")
if(name == "all"){
id <- seq_len(length(x))
if(length(id)==0){
cat("Folder is empty.\n")
} else {
names <- sapply(names(x), function(x) transform_name(x, back = TRUE))
length_notes <- unlist(lapply(x,length))
out <- data.frame("Names" = names, "Notes" = length_notes, row.names = NULL)
cat("Files","\n")
print(out)
}
} else {
tname <- transform_name(name)
if(!tname %in% names(x)){
cat("No file for",paste0(name,"."),"\n")
} else {
file <- x[[tname]]
id <- seq_len(length(file))
if(length(id)==0){
cat("File of",name,"is empty.\n")
} else {
dates <- unlist(lapply(file, function(x) as.character(x[["date"]])))
notes <- unlist(lapply(file, function(x) as.character(x[["note"]])))
out <- data.frame("Date" = dates, "Note" = notes, row.names = id)
cat(name,"\n")
print(out)
}
}
}
return(invisible(x))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.