From a38fe470a8aaa1ed9922e95e76e77c74f4a50b69 Mon Sep 17 00:00:00 2001 From: Saturnino Luz <luzs@acm.org> Date: Thu, 10 Aug 2017 10:37:10 +0100 Subject: [PATCH] Fixed conditional dependency on igraph package --- DESCRIPTION | 2 +- R/markov.R | 66 ++++++++++++++++++++---------------- R/vocalgraphs.R | 3 +- man/identifyVocalisations.Rd | 6 ++-- man/igraph.vocaldia.Rd | 4 ++- man/plot.vocaldia.Rd | 9 ++--- man/toDotNotation.Rd | 5 +-- man/write.vocaldia.Rd | 7 ++-- 8 files changed, 56 insertions(+), 46 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9ad4bda..3df33c3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,7 @@ LazyData: true Package: vocaldia Type: Package Title: Create and Manipulate Vocalisation Diagrams -Version: 0.8.1 +Version: 0.8.2 Date: 2017-04-03 Authors@R: person("Saturnino", "Luz", email = "luzs@acm.org", role = c("aut", "cre")) Description: Create adjacency matrices of vocalisation graphs from diff --git a/R/markov.R b/R/markov.R index 7dc0e60..9948dc8 100644 --- a/R/markov.R +++ b/R/markov.R @@ -317,12 +317,12 @@ identifyPauses <- function(vocvector){ ##' ##' E.g (speakers A, B, C): ##' \preformatted{ -##' AAAAAAAABBBBBBBCCCCCBBBBBPauseBBBBSwitchingPauseAAAAAGrpVocalisation +##' AAAAAAAABBBBBBBCCCCCBBBBBPauseBBBBSwitchingPauseAAAAAGrp ##' ^ ^ ^ ^ ^ ^ ##' | | | | | | -##' | | | ---------------- Non-SwitchingVocalisation's +##' | | | ----------- Non-SwitchingVocalisation ##' | | | -##' ---------------------> SwitchingVocalisation's +##' ---------------------> SwitchingVocalisation ##' } ##' ##' @title identifyVocalisations: replace appropriate vocalisation @@ -417,23 +417,21 @@ getEntropy <- function (distribution){ ##' Plot a vocalisation diagram ##' @title plot.vocaldia ##' @param x a vocalisation diagram -##' @param package the package to be used for ploting (igraph -##' (default) or Rgraphviz) ##' @param ... arguments for the layout algorithm ##' @return \code{NULL} ##' @examples ##' data(vocdia) -##' require('igraph') -##' plot(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), +##' if (require('igraph')) +##' plot(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), ##' individual=TRUE, nodecolumn='speaker')) ##' @export -plot.vocaldia <- function(x, ..., package='igraph'){ - vd <- x - if (requireNamespace("igraph", quietly = TRUE)){ - ## require('igraph') - g <- igraph.vocaldia(vd) - plot(g, layout=igraph::layout.fruchterman.reingold(g), ...) - return(g) +plot.vocaldia <- function(x, ...){ + x + if (requireNamespace('igraph', quietly = TRUE)){ + ## require('igraph') + g <- igraph.vocaldia(x) + plot(g, layout=igraph::layout.fruchterman.reingold(g), ...) + return(g) } ##if (requireNamespace("Rgraphviz", quietly = TRUE)){ ## cat('Rgraphviz support under construction. PLease use igraph instead') @@ -449,7 +447,7 @@ plot.vocaldia <- function(x, ..., package='igraph'){ ## plot(g, edgeAttrs=ea, attrs=at, ...) ## return(g) ##} - warning(paste('Package ',package, ' not supported. Try igraph.')) + warning(paste('Package igraph not installed. Try installing igraph or "require(igraph)" if installed.')) } @@ -462,16 +460,22 @@ plot.vocaldia <- function(x, ..., package='igraph'){ ##' @return an igraph ##' @examples ##' data(vocdia) -##' igraph.vocaldia(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), +##' if (require('igraph')) +##' igraph.vocaldia(getSampledVocalMatrix(subset(atddia, +##' id=='Abbott_Maddock_01'), ##' individual=TRUE, nodecolumn='speaker')) ##' @export igraph.vocaldia <- function(vd, ...){ - g <- igraph::graph.adjacency(vd$ttarray, weighted=T) - igraph::V(g)$label <- names(vd$ttarray[1,]) - igraph::E(g)$label <- round(igraph::E(g)$weight,digits=3) - igraph::V(g)$size <- 25*exp(vd$tdarray) - g$layout <- igraph::layout.kamada.kawai(g) - g + if (requireNamespace('igraph', quietly = TRUE)){ + g <- igraph::graph.adjacency(vd$ttarray, weighted=T) + igraph::V(g)$label <- names(vd$ttarray[1,]) + igraph::E(g)$label <- round(igraph::E(g)$weight,digits=3) + igraph::V(g)$size <- 25*exp(vd$tdarray) + g$layout <- igraph::layout.kamada.kawai(g) + return(g) + } + else + warning(paste('Package igraph not supported. Try installing igraph or "require(igraph)" if installed.')) } ## ##' Create a graphNEL vocalisation diagram @@ -501,9 +505,10 @@ igraph.vocaldia <- function(vd, ...){ ##' @return \code{NULL} ##' @examples ##' data(vocdia) -##' write.vocaldia(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), -##' individual=TRUE, nodecolumn='speaker'), -##' file=tempfile(pattern='vocaldia-', fileext='.dot') ) +##' write.vocaldia(getSampledVocalMatrix(subset(atddia, +##' id=='Abbott_Maddock_01'), +##' individual=TRUE, nodecolumn='speaker'), +##' file=tempfile(pattern='vocaldia-', fileext='.dot')) ##' @export write.vocaldia <- function(vd, file="", ...){ o <- toDotNotation(vd, ...) @@ -528,12 +533,15 @@ write.vocaldia <- function(vd, file="", ...){ ##' @return character data containing the diagram in dot format. ##' @examples ##' data(vocdia) -##' toDotNotation(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), -##' individual=TRUE, nodecolumn='speaker')) +##' toDotNotation(getSampledVocalMatrix(subset(atddia, +##' id=='Abbott_Maddock_01'), +##' individual=TRUE, nodecolumn='speaker')) ##' @seealso graphviz manual ##' @export -toDotNotation <- function(vd, individual=T, varsizenode=T, shape='circle', - fontsize=16, rankdir='LR', nodeattribs='fixedsize=true;', +toDotNotation <- function(vd, individual=T, varsizenode=T, + shape='circle', + fontsize=16, rankdir='LR', + nodeattribs='fixedsize=true;', comment="") { head <- paste("## diagram generated by vocalgraphs.r\n## ", comment, diff --git a/R/vocalgraphs.R b/R/vocalgraphs.R index a8f294a..3e7a633 100644 --- a/R/vocalgraphs.R +++ b/R/vocalgraphs.R @@ -421,7 +421,8 @@ getTurnTakingProbMatrix <- function(df, individual=FALSE, ...) ##' getTurnTakingMatrix(x) ##' getTurnTakingMatrix(x, individual=TRUE) ##' @export -getTurnTakingMatrix <- function(df, begin='begin', end='end', nodecolumn='role', +getTurnTakingMatrix <- function(df, begin='begin', end='end', + nodecolumn='role', individual=FALSE, noPauseTypes=FALSE) { ##df <- subset(df, df$id %in% ids) diff --git a/man/identifyVocalisations.Rd b/man/identifyVocalisations.Rd index 87e3038..e60a836 100644 --- a/man/identifyVocalisations.Rd +++ b/man/identifyVocalisations.Rd @@ -28,12 +28,12 @@ speaker (as opposed to speaker to Grp or speaker to Pause). E.g (speakers A, B, C): \preformatted{ -AAAAAAAABBBBBBBCCCCCBBBBBPauseBBBBSwitchingPauseAAAAAGrpVocalisation +AAAAAAAABBBBBBBCCCCCBBBBBPauseBBBBSwitchingPauseAAAAAGrp ^ ^ ^ ^ ^ ^ | | | | | | - | | | ---------------- Non-SwitchingVocalisation's + | | | ----------- Non-SwitchingVocalisation | | | - ---------------------> SwitchingVocalisation's + ---------------------> SwitchingVocalisation } } \examples{ diff --git a/man/igraph.vocaldia.Rd b/man/igraph.vocaldia.Rd index 0f31590..e0e0af1 100644 --- a/man/igraph.vocaldia.Rd +++ b/man/igraph.vocaldia.Rd @@ -22,6 +22,8 @@ Create a vocalisation diagram } \examples{ data(vocdia) -igraph.vocaldia(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), +if (require('igraph')) + igraph.vocaldia(getSampledVocalMatrix(subset(atddia, + id=='Abbott_Maddock_01'), individual=TRUE, nodecolumn='speaker')) } diff --git a/man/plot.vocaldia.Rd b/man/plot.vocaldia.Rd index ad47186..d3b7ba0 100644 --- a/man/plot.vocaldia.Rd +++ b/man/plot.vocaldia.Rd @@ -4,15 +4,12 @@ \alias{plot.vocaldia} \title{plot.vocaldia} \usage{ -\method{plot}{vocaldia}(x, ..., package = "igraph") +\method{plot}{vocaldia}(x, ...) } \arguments{ \item{x}{a vocalisation diagram} \item{...}{arguments for the layout algorithm} - -\item{package}{the package to be used for ploting (igraph -(default) or Rgraphviz)} } \value{ \code{NULL} @@ -25,7 +22,7 @@ Plot a vocalisation diagram } \examples{ data(vocdia) -require('igraph') -plot(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), +if (require('igraph')) + plot(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), individual=TRUE, nodecolumn='speaker')) } diff --git a/man/toDotNotation.Rd b/man/toDotNotation.Rd index c21731e..f44d87c 100644 --- a/man/toDotNotation.Rd +++ b/man/toDotNotation.Rd @@ -36,8 +36,9 @@ Create a vocalisation diagram in dot notation } \examples{ data(vocdia) -toDotNotation(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), - individual=TRUE, nodecolumn='speaker')) +toDotNotation(getSampledVocalMatrix(subset(atddia, + id=='Abbott_Maddock_01'), + individual=TRUE, nodecolumn='speaker')) } \seealso{ graphviz manual diff --git a/man/write.vocaldia.Rd b/man/write.vocaldia.Rd index 4f0c059..f548b6e 100644 --- a/man/write.vocaldia.Rd +++ b/man/write.vocaldia.Rd @@ -24,7 +24,8 @@ Write a vocalisation diagram } \examples{ data(vocdia) -write.vocaldia(getSampledVocalMatrix(subset(atddia, id=='Abbott_Maddock_01'), - individual=TRUE, nodecolumn='speaker'), - file=tempfile(pattern='vocaldia-', fileext='.dot') ) +write.vocaldia(getSampledVocalMatrix(subset(atddia, + id=='Abbott_Maddock_01'), + individual=TRUE, nodecolumn='speaker'), + file=tempfile(pattern='vocaldia-', fileext='.dot')) } -- GitLab