Skip to content

Commit

Permalink
Merge pull request #16 from moshejasper/dev
Browse files Browse the repository at this point in the history
generics & class updates (not reverse compatible in all cases)
  • Loading branch information
moshejasper authored Dec 9, 2020
2 parents 3a92ecf + 6c50410 commit 1fbfd6f
Show file tree
Hide file tree
Showing 43 changed files with 1,010 additions and 417 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: kindisperse
Title: Simulate and Estimate Close-Kin Dispersal Kernels
Version: 0.4.2
Version: 0.4.3
Authors@R:
person(given = "Moshe-Elijah",
family = "Jasper",
Expand Down
37 changes: 36 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Generated by roxygen2: do not edit by hand

export("breedsigma<-")
export("category<-")
export("dsigma<-")
export("filtertype<-")
export("gravsigma<-")
export("juvsigma<-")
export("kerneltype<-")
export("lifestage<-")
export("lower<-")
export("ovisigma<-")
export("sampledims<-")
export("samplenum<-")
export("simdims<-")
export("simtype<-")
export("spacing<-")
export("upper<-")
export(KinPairSimulation_composite)
export(KinPairSimulation_simple)
export(axials)
Expand All @@ -13,17 +27,32 @@ export(axials_subtract)
export(axpermute)
export(axpermute_standard)
export(axpermute_subtract)
export(breedsigma)
export(category)
export(distances)
export(dsigma)
export(filtertype)
export(gravsigma)
export(is.KinPairData)
export(is.KinPairSimulation)
export(juvsigma)
export(kerneltype)
export(lifestage)
export(lower)
export(ovisigma)
export(run_kindisperse)
export(sample_kindist)
export(sampledims)
export(samplenum)
export(simdims)
export(simgraph_data)
export(simgraph_graph)
export(simtype)
export(simulate_kindist_composite)
export(simulate_kindist_simple)
export(spacing)
export(to_tibble)
export(upper)
exportClasses(KinPairData)
exportClasses(KinPairSimulation)
exportMethods("category<-")
Expand All @@ -36,18 +65,22 @@ exportMethods("upper<-")
exportMethods(breedsigma)
exportMethods(category)
exportMethods(distances)
exportMethods(dsigma)
exportMethods(filtertype)
exportMethods(gravsigma)
exportMethods(initialize)
exportMethods(juvsigma)
exportMethods(kerneltype)
exportMethods(lifestage)
exportMethods(lower)
exportMethods(ovisigma)
exportMethods(sampledims)
exportMethods(samplenum)
exportMethods(sigma)
exportMethods(show)
exportMethods(simdims)
exportMethods(simtype)
exportMethods(spacing)
exportMethods(to_tibble)
exportMethods(upper)
importClassesFrom(tibble,tbl_df)
importFrom(dplyr,everything)
Expand Down Expand Up @@ -82,11 +115,13 @@ importFrom(grid,arrow)
importFrom(grid,unit)
importFrom(here,here)
importFrom(magrittr,"%>%")
importFrom(methods,initialize)
importFrom(methods,is)
importFrom(methods,new)
importFrom(methods,setGeneric)
importFrom(methods,setMethod)
importFrom(methods,setValidity)
importFrom(methods,show)
importFrom(methods,validObject)
importFrom(plotly,ggplotly)
importFrom(plotly,plotlyOutput)
Expand Down
115 changes: 78 additions & 37 deletions R/KinPairData.R
Original file line number Diff line number Diff line change
@@ -1,128 +1,160 @@
methods::setOldClass(c("tbl_df", "tbl", "data.frame"))

#' Title
#' Formal class "KinPairData"
#'
#' @description The class \code{KinPairData} is a formal (S4) class for storing kinship and lifespan dispersal information concerning kin pairs.
#' @slot category character.
#' @slot lifestage character.
#' @slot tab tbl_df.
#'
#' @return
#' @export
#'
#' @examples
#'
KinPairData <- setClass("KinPairData",
slots = list(category = "character", lifestage = "character", tab = "tbl_df"))

#' Title

######### GENERICS and METHODS#############

#' Extract KinPairData to tibble (generic)
#'
#' @param x
#' @param x object of class \code{KinPairData}
#'
#' @return tibble (class \code{tbl_df})
#' @export
#'
#'
setGeneric("to_tibble", function(x) standardGeneric("to_tibble"))

#'
#'
#' @param KinPairData
#'
#' @return
#' @export
#'
#' @examples
#' @describeIn KinPairData extract to tibble
setMethod("to_tibble", "KinPairData", function(x) x@tab)

#' Access or assign kin category (generic for KinPairData class)
#'
#' @param x object with relevant method
#'
#' @return \code{character}. Kinship category of object
#' @export
#'
setGeneric("category", function(x) standardGeneric("category"))
#' Title
#'
#' @param x
#' @param value
#' @rdname category
#' @param x object with relevant method
#' @param value new value to assign
#'
#' @return
#' @return returns modified object
#' @export
#'
#' @examples
#'
setGeneric("category<-", function(x, value) standardGeneric("category<-"))
#' Title
#' Access or assign lifestage (generic for KinPairData class)
#'
#' @param x
#' @param x object with relevant method
#'
#' @return
#' @export
#'
#' @examples
#'
setGeneric("lifestage", function(x) standardGeneric("lifestage"))
#' Title
#'
#' @param x
#' @param value
#' @rdname lifestage
#' @param x object with relevant method
#' @param value new value to assign
#'
#' @return
#' @export
#'
#' @examples
#'
setGeneric("lifestage<-", function(x, value) standardGeneric("lifestage<-"))

#' Access distances (generic for KinPairData Class)
#' Access distances (generic for KinPairData class)
#'
#' @param x Object of Class KinPairData
#'
#' @return Returns a numeric vector of kin separation distances
#' @export
#'
#' @examples
#'
setGeneric("distances", function(x) standardGeneric("distances"))


#' Title


#'
#' @param KinPairData
#'
#' @param KinPairData object of class \code{KinPairData}
#'
#' @return
#' @export
#'
#' @examples
#' @describeIn KinPairData access distances
setMethod("distances", "KinPairData", function(x) x@tab$distance)

#' Access or assign KinPairData kin category
#' @name category
#' @param KinPairData
#'
#'
#' @param KinPairData object of class \code{KinPairData}
#'
#' @return
#' @export
#'
#' @examples
#' @describeIn KinPairData access kin category
setMethod("category", "KinPairData", function(x) x@category)

#'
#' @rdname category
#' @param KinPairData
#'
#' @param KinPairData object of class \code{KinPairData}
#'
#' @return
#' @export
#'
#' @examples
#' @describeIn KinPairData assign kin category
setMethod("category<-", "KinPairData", function(x, value){
x@category <- value
validObject(x)
x
})


#' Access or assign KinPairData lifestage
#' @name lifestage
#'
#'
#' @param KinPairData
#'
#' @return
#' @export
#'
#' @examples
#' @describeIn KinPairData access lifestage
setMethod("lifestage", "KinPairData", function(x) x@lifestage)

#'
#'
#' @rdname lifestage
#'
#' @param KinPairData
#'
#' @return
#' @export
#'
#' @examples
#' @describeIn KinPairData assign lifestage
setMethod("lifestage<-", "KinPairData", function(x, value){
x@lifestage <- value
validObject(x)
x
})

#'
#'
#' @param KinPairData
#'
#' @return
#' @export
#'
#' @describeIn KinPairData standard print method
setMethod(
"show",
"KinPairData",
Expand All @@ -139,6 +171,14 @@ setMethod(

# Constructor method of KinPairData

#' Title
#'
#' @param KinPairData
#'
#' @return
#' @export
#'
#' @describeIn KinPairData initialize method
setMethod("initialize", "KinPairData",
function(.Object,
data,
Expand Down Expand Up @@ -199,6 +239,7 @@ setMethod("initialize", "KinPairData",
}
)


setValidity("KinPairData", function(object){
if (! object@category %in% c("UN", "PO", "GG", "GGG", "FS", "AV", "GAV", "1C", "1C1", "2C", "HS", "HAV", "HGAV", "H1C", "H1C1", "H2C")) {
"@category must be one of UN PO GG GGG FS AV GAV 1C 1C1 2C HS HAV HGAV H1C H1C1 H2C"
Expand All @@ -214,10 +255,10 @@ setValidity("KinPairData", function(object){
#'
#' @param x object to be checked
#'
#' @return Returns TRUE if of class KinPairData, FALSE if not.
#' @return Returns TRUE if of class \code{KinPairData}, FALSE if not.
#' @export
#'
#' @examples
#'
is.KinPairData <- function(x){
"KinPairData" %in% is(x)
}
Loading

0 comments on commit 1fbfd6f

Please sign in to comment.