Я создаю класс S4 и пишу метод для этого класса.Я документирую этот класс, используя документацию roxygen2.Ниже приведен пример моего кодирования и документации.
#' Class Clustering
#' Partition data into clusters
#' @name Clustering-class
#' @rdname Clustering-class
#'
#' @slot Cluster List of matrices, where each element of the list grasps data belongs to a single cluster as a matrix
#' @slot Centers Matrix of cluster centers
#' @slot k No of centers
#'
#' @import flexclust clusterGeneration
#' @exportClass Clustering
#' @export Clustering
Clustering <- setClass("Clustering",
slots = c(
Cluster = "list",
k = "numeric",
Centers = "matrix"
)
)
#' Clustering.
#' @name Clusters
#' @rdname clusters-methods
setGeneric("Clusters",
def = function(object, x, k)
{
standardGeneric("Clusters")
}
)
#' Partition data into clusters
#' @description Initilaize slots of class \code{Clustering} by partitioning data set into 'k' clusters.
#'
#' @rdname Clusters-methods
#' @aliases Clusters,Clustering-method
#'
#' @param object An object of class \code{Clustering}.
#' @param x Numeric matrix of data.
#' @param k Number of centers.
#'
#' @details Runs 'flexclust' clustering algorithm with default settings i.e.
#' method = "kmeans", dist = "euclidean", and partition the data set.
#' @importFrom flexclust cclust
#' @exportMethod Clusters
#'
#' @examples
#' x <- rbind(matrix(rnorm(150, mean = 5, sd = 0.5), ncol = 2),
#' matrix(rnorm(100, mean = 15, sd = 0.5), ncol = 2),
#' matrix(rnorm(200, mean = 30, sd = 0.5), ncol = 2))
#' obj <- Clustering()
#'
#' Clusters(obj, x = x, k = 3)
#'
#' @return An object of class \code{Clustering}
#'
setMethod("Clusters",
signature(object = "Clustering", x = "matrix", k = "numeric"),
definition = function(object, x, k)
{
fit <- flexclust::cclust(x, k, dist = "euclidean", method = "kmeans")
for(i in 1:k)
object@Cluster[[i]] <- x[fit@cluster==i,]
object@Centers <- fit@centers
object@k <- k
return(object)
}
)
Когда я проверяю пакет, он выдает мне предупреждение
проверка на отсутствие записей документации ... ПРЕДУПРЕЖДЕНИЕ Недокументированные объекты кода: «Кластеры» Недокументированные классы S4: «Кластеризация»«Все объекты уровня пользователя в пакете (включая классы и методы S4) должны иметь записи документации.См. Главу «Написание файлов документации R» в руководстве «Написание R-расширений».Я не знаю, как решить проблему и какая документация roxygen2 отсутствует.