SCM

SCM Repository

[matrix] Diff of /pkg/R/Auxiliaries.R
ViewVC logotype

Diff of /pkg/R/Auxiliaries.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 972, Fri Oct 7 20:13:24 2005 UTC revision 973, Fri Oct 7 20:15:08 2005 UTC
# Line 234  Line 234 
234                     factors = list()), ## FIXME: treat 'factors' smartly                     factors = list()), ## FIXME: treat 'factors' smartly
235                 from)                 from)
236  }  }
237    
238    
239    try_as <- function(x, classes, tryAnyway = FALSE) {
240        if(!tryAnyway && !is(x, "Matrix"))
241            return(x)
242        ## else
243        ok <- canCoerce(x, classes[1])
244        while(!ok && length(classes <- classes[-1])) {
245            ok <- canCoerce(x, classes[1])
246        }
247        if(ok) as(x, classes[1]) else x
248    }
249    
250    ## MM thinks the following should become part of 'methods' :
251    canCoerce <- function(object, Class) {
252      ## Purpose:  test if 'object' is coercable to 'Class', i.e.,
253      ##           as(object, Class) will {typically} work
254      ## ----------------------------------------------------------------------
255      ## Author: John Chambers, Date:  6 Oct 2005
256       is(object, Class) ||
257       !is.null(selectMethod("coerce", c(class(object), Class),
258                             optional = TRUE,
259                             useInherited = c(from = TRUE, to = FALSE)))
260    }
261    

Legend:
Removed from v.972  
changed lines
  Added in v.973

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge