Revision: 1288
http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1288&view=rev
Author: warnes
Date: 2008-06-11 17:29:28 -0700 (Wed, 11 Jun 2008)
Log Message:
-----------
Update source code, improve documentation
Modified Paths:
--------------
trunk/SII/R/print.SII.R
trunk/SII/R/reload.constants.R
trunk/SII/R/sii.R
trunk/SII/R/sii.excel.R
Added Paths:
-----------
trunk/SII/R/summary.SII.R
Modified: trunk/SII/R/print.SII.R
===================================================================
--- trunk/SII/R/print.SII.R 2008-06-12 00:28:49 UTC (rev 1287)
+++ trunk/SII/R/print.SII.R 2008-06-12 00:29:28 UTC (rev 1288)
@@ -1,5 +1,7 @@
`print.SII` <-
function (x, digits = 2, ...)
{
- print(unclass(round(x$sii, digits)))
+ cat("\n")
+ cat("SII:", round(x$sii, digits), "\n")
+ cat("\n")
}
Modified: trunk/SII/R/reload.constants.R
===================================================================
--- trunk/SII/R/reload.constants.R 2008-06-12 00:28:49 UTC (rev 1287)
+++ trunk/SII/R/reload.constants.R 2008-06-12 00:29:28 UTC (rev 1288)
@@ -1,6 +1,10 @@
reload.constants <- function(xls.path,rda.path=xls.path)
{
+
+ if(!require("gdata"))
+ stop("'gdata' package must be installed to run this function.")
+
"critical" <- read.xls(
xls=file.path(xls.path,"SII_Constants.xls"),
sheet=1,
@@ -72,8 +76,8 @@
"sic.octave" <- read.xls(
xls=file.path(xls.path,"SII_Constants.xls"),
- sheet=4,
- skip=5,
+ sheet=7,
+ skip=3,
header=TRUE,
nrows=6,
check.names=FALSE,
Modified: trunk/SII/R/sii.R
===================================================================
--- trunk/SII/R/sii.R 2008-06-12 00:28:49 UTC (rev 1287)
+++ trunk/SII/R/sii.R 2008-06-12 00:29:28 UTC (rev 1288)
@@ -7,8 +7,8 @@
method=c(
"interpolate",
"critical",
+ "equal-contributing",
"one-third octave",
- "equal-contributing",
"octave"
),
importance=c(
@@ -59,16 +59,23 @@
table <- get(data.name)
## Get the correct importance functions
- importance=match.arg(importance)
- if(importance!="SII")
+ if(missing(importance) || is.character(importance) )
{
- sic.name <- paste("sic.",data.name, sep="")
- data(list=sic.name, package="SII")
- sic.table <- get(sic.name)
- table[,"Ii"] <- sic.table[[importance]]
+ importance=match.arg(importance)
+ if(importance!="SII")
+ {
+ sic.name <- paste("sic.",data.name, sep="")
+ data(list=sic.name, package="SII")
+ sic.table <- get(sic.name)
+ table[,"Ii"] <- sic.table[[importance]]
+ }
}
+ else
+ if(length(importance) != nrow(table))
+ stop("`importance' vector have length ", nrow(table), "for method `",method,"'.")
+ else
+ table[,"Ii"] <- importance
-
## Handle missing freq
if(missing(freq))
@@ -355,8 +362,9 @@
retval$threshold <- threshold
retval$loss <- loss
retval$freq <- freq
+ retval$method <- method
+ retval$table <- sii.tab
retval$sii <- sii.val
- retval$table <- sii.tab
class(retval) <- "SII"
Modified: trunk/SII/R/sii.excel.R
===================================================================
--- trunk/SII/R/sii.excel.R 2008-06-12 00:28:49 UTC (rev 1287)
+++ trunk/SII/R/sii.excel.R 2008-06-12 00:29:28 UTC (rev 1288)
@@ -4,6 +4,9 @@
matlab.spline=TRUE
)
{
+ if(!require("splines"))
+ stop("'splines' package must be installed to run this function.")
+
if(length(THDI) != length(freq))
stop("THDI must have the same length as freq")
Added: trunk/SII/R/summary.SII.R
===================================================================
--- trunk/SII/R/summary.SII.R (rev 0)
+++ trunk/SII/R/summary.SII.R 2008-06-12 00:29:28 UTC (rev 1288)
@@ -0,0 +1,30 @@
+`summary.SII` <-
+function (x, digits = 2, ...)
+{
+ cat("\n")
+ cat("Speech Intellibility Index\n")
+ cat("--------------------------\n")
+ cat("\n")
+ cat("Call:\n")
+ cat("\n")
+ print(x$call)
+ cat("\n")
+ methodStr <- switch(x$method,
+ "interpolate"="Interpolation + Critical Band",
+ "critical"="Critical band SII procedure",
+ "equal-contributing"="Equally-contrlbutlng (17 band) critical-band SII procedure ",
+ "one-third octave"="One-third octave band SII procedure",
+ "octave"="Octave band SII procedure"
+ )
+
+ cat("Method:", methodStr, "\n" )
+ cat("\n")
+ cat("Calculation table:\n")
+ cat("\n")
+ print(round(x$table, digits=digits))
+ cat("\n")
+ cat("SII:", round(x$sii, digits), "\n")
+ cat("\n")
+ invisible(x)
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|