@@ -177,7 +177,7 @@ txtPval <- function(pvalues,
177177# '
178178# ' @param x The value/vector/data.frame/matrix to be rounded
179179# ' @param digits The number of digits to round each element to.
180- # ' If you provide a vector each element for corresponding columns.
180+ # ' If you provide a vector each element will apply to the corresponding columns.
181181# ' @param excl.cols Columns to exclude from the rounding procedure.
182182# ' This can be either a number or regular expression. Skipped if x is a vector.
183183# ' @param excl.rows Rows to exclude from the rounding procedure.
@@ -205,7 +205,13 @@ txtRound <- function(x, ...){
205205# ' @export
206206# ' @rdname txtRound
207207txtRound.default = function (x , digits = 0 , txt.NA = " " , dec = " ." , ... ){
208- if (length(digits ) > length(x )) stop(" You have " , length(digits ), " but only a vector of length " , length(x ), " : " , paste(x , collape = " , " ))
208+ if (length(digits ) != 1 & length(digits ) != length(x ))
209+ stop(" You have " ,
210+ length(digits ),
211+ " digits specifications but a vector of length " ,
212+ length(x ),
213+ " : " ,
214+ paste(x , collapse = " , " ))
209215
210216 dec_str <- sprintf(" ^[^0-9\\ %s-]*([\\ -]{0,1}(([0-9]*|[0-9]+[ 0-9]+)[\\ %s]|)[0-9]+)(|[^0-9]+.*)$" ,
211217 dec , dec )
@@ -281,7 +287,13 @@ txtRound.matrix <- function(x, digits = 0, excl.cols, excl.rows, ...){
281287 if (length(rows ) == 0 )
282288 stop(" No rows to round" )
283289
284- if (length(digits ) > length(cols )) stop(" You have " , length(digits ), " but only " , length(cols ), " to apply them to: " , paste(cols , collape = " , " ))
290+ if (length(digits ) != 1 & length(digits ) != length(cols ))
291+ stop(" You have " ,
292+ length(digits ),
293+ " digits specifications but " ,
294+ length(cols ),
295+ " columns to apply them to: " ,
296+ paste(cols , collapse = " , " ))
285297
286298 ret_x <- x
287299 for (row in rows ){
0 commit comments