EVOLUTION-MANAGER
Edit File: list.clean.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: Clean a list by a function</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 list.clean {rlist}"><tr><td>list.clean {rlist}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Clean a list by a function</h2> <h3>Description</h3> <p>This function removes all elements evaluated to be <code>TRUE</code> by an indicator function. The removal can be recursive so that the resulted list surely does not include such elements in any level. </p> <h3>Usage</h3> <pre> list.clean(.data, fun = is.null, recursive = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.data</code></td> <td> <p>A <code>list</code> or <code>vector</code> to operate over.</p> </td></tr> <tr valign="top"><td><code>fun</code></td> <td> <p>A <code>character</code> or a <code>function</code> that returns <code>TRUE</code> or <code>FALSE</code> to indicate if an element of <code>.data</code> should be removed.</p> </td></tr> <tr valign="top"><td><code>recursive</code></td> <td> <p><code>logical</code>. Should the list be cleaned recursively? Set to FALSE by default.</p> </td></tr> </table> <h3>Details</h3> <p>Raw data is usually not completely ready for analysis, and needs to be cleaned up to certain standards. For example, some data operations require that the input does not include <code>NULL</code> values in any level, therefore <code>fun = "is.null"</code> and <code>recursive = TRUE</code> can be useful to clean out all <code>NULL</code> values in a list at any level. </p> <p>Sometimes, not only <code>NULL</code> values are undesired, empty vectors or lists are also unwanted. In this case, <code>fun = function(x) length(x) == 0L</code> can be useful to remove all empty elements of zero length. This works because <code>length(NULL) == 0L</code>, <code>length(list()) == 0L</code> and <code>length(numeric()) == 0L</code> are all <code>TRUE</code>. </p> <h3>Examples</h3> <pre> x <- list(a=NULL,b=list(x=NULL,y=character()),d=1,e=2) list.clean(x) list.clean(x, recursive = TRUE) list.clean(x, function(x) length(x) == 0L, TRUE) </pre> <hr /><div style="text-align: center;">[Package <em>rlist</em> version 0.4.6.2 <a href="00Index.html">Index</a>]</div> </body></html>