EVOLUTION-MANAGER
Edit File: guides.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Generic Methods to Implement Flexible Guide Line Computations</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for guides {diffobj}"><tr><td>guides {diffobj}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Generic Methods to Implement Flexible Guide Line Computations</h2> <h3>Description</h3> <p>Guides are context lines that would normally be omitted from the diff because they are too far from any differences, but provide particularly useful contextual information. Column headers are a common example. Modifying guide finding is an advanced feature intended for package developers that want special treatment for the display output of their objects. </p> <h3>Usage</h3> <pre> guidesPrint(obj, obj.as.chr) ## S4 method for signature 'ANY,character' guidesPrint(obj, obj.as.chr) guidesStr(obj, obj.as.chr) ## S4 method for signature 'ANY,character' guidesStr(obj, obj.as.chr) guidesChr(obj, obj.as.chr) ## S4 method for signature 'ANY,character' guidesChr(obj, obj.as.chr) guidesDeparse(obj, obj.as.chr) ## S4 method for signature 'ANY,character' guidesDeparse(obj, obj.as.chr) guidesFile(obj, obj.as.chr) ## S4 method for signature 'ANY,character' guidesFile(obj, obj.as.chr) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>obj</code></td> <td> <p>an R object</p> </td></tr> <tr valign="top"><td><code>obj.as.chr</code></td> <td> <p>the character representation of <code>obj</code> that is used for computing the diffs</p> </td></tr> </table> <h3>Details</h3> <p><code>Diff</code> detects these important context lines by looking for patterns in the text of the diff, and then displays these lines in addition to the normal diff output. Guides are marked by a tilde in the gutter, and are typically styled differently than normal context lines, by default in grey. Guides may be far from the diff hunk they are juxtaposed to. We eschew the device of putting the guides in the hunk header as <code>git diff</code> does because often the column alignment of the guide line is meaningful. </p> <p>Guides are detected by the <code>guides*</code> methods documented here. Each of the <code>diff*</code> methods (e.g. <code><a href="diffPrint.html">diffPrint</a></code>) has a corresponding <code>guides*</code> method (e.g. <code><a href="guides.html">guidesPrint</a></code>), with the exception of <code><a href="diffCsv.html">diffCsv</a></code> since that method uses <code>diffPrint</code> internally. The <code>guides*</code> methods expect an R object as the first parameter and the captured display representation of the object in a character vector as the second. The function should then identify which elements in the character representation should be treated as guides, and should return the numeric indices for them. </p> <p>The original object is passed as the first argument so that the generic can dispatch on it, and so the methods may adjust their guide finding behavior to data that is easily retrievable from the object, but less so from the character representation thereof. </p> <p>The default method for <code>guidesPrint</code> has special handling for 2D objects (e.g. data frames, matrices), arrays, time series, tables, lists, and S4 objects that use the default <code>show</code> method. Guide finding is on a best efforts basis and may fail if your objects contain “pathological” display representations. Since the diff will still work with failed <code>guides</code> finding we consider this an acceptable compromise. Guide finding is more likely to fail with nested recursive structures. A known issue is that list-like S3 objects without print methods [reset the tag buffers](https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17610) so the guides become less useful for them. </p> <p><code>guidesStr</code> highlights top level objects. The default methods for the other <code>guide*</code> generics do not do anything and exist only as a mechanism for providing custom guide line methods. </p> <p>If you dislike the default handling you can also define your own methods for matrices, arrays, etc., or alternatively you can pass a guide finding function directly via the <code>guides</code> parameter to the <code>diff*</code> methods. </p> <p>If you have classed objects with special patterns you can define your own methods for them (see examples), though if your objects are S3 you will need to use <code><a href="../../methods/html/setOldClass.html">setOldClass</a></code> as the <code>guides*</code> generics are S4. </p> <h3>Value</h3> <p>integer containing values in <code>seq_along(obj.as.chr)</code> </p> <h3>Note</h3> <p>The mechanism for identifying guides will almost certainly change in the future to allow for better handling of nested guides, so if you do implement custom guideline methods do so with the understanding that they will likely be deprecated in one of the future releases. </p> <h3>Examples</h3> <pre> ## Roundabout way of suppressing guides for matrices setMethod("guidesPrint", c("matrix", "character"), function(obj, obj.as.chr) integer(0L) ) ## Special guides for "zulu" S3 objects that match lines ## starting in "zulu###" where ### is a nuber setOldClass("zulu") setMethod("guidesPrint", c("zulu", "character"), function(obj, obj.as.chr) { if(length(obj) > 20) grep("^zulu[0-9]*", obj.as.chr) else integer(0L) } ) </pre> <hr /><div style="text-align: center;">[Package <em>diffobj</em> version 0.3.5 <a href="00Index.html">Index</a>]</div> </body></html>