EVOLUTION-MANAGER
Edit File: utilities.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: Printing, reading and writing compiled function objects</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 utilities {inline}"><tr><td>utilities {inline}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Printing, reading and writing compiled function objects </h2> <h3>Description</h3> <p><code>moveDLL</code> moves the DLL used by a compiled function to a user defined location. </p> <p><code>writeCFunc</code> saves a <code>CFunc</code> object after the DLL has been moved to the desired location using <code>moveDLL</code>. </p> <p><code>readCFunc</code> reads a <code>CFunc</code> object that has been saved using <code>writeCFunc</code>. </p> <p>The <code>print</code> and <code>code</code> methods respectively print the entire object or only the code parts. </p> <h3>Usage</h3> <pre> moveDLL(x, ...) ## S4 method for signature 'CFunc' moveDLL(x, name, directory, unload = FALSE, overwrite = FALSE, verbose = FALSE) writeCFunc(x, file) readCFunc(file) ## S4 method for signature 'CFunc' print(x) ## S4 method for signature 'CFuncList' print(x) ## S4 method for signature 'CFunc' code(x, linenumbers = TRUE) ## S4 method for signature 'CFuncList' code(x, linenumbers = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A <code>CFunc</code> or <code>CFuncList</code> object as created by <code><a href="cfunction.html">cfunction</a></code></p> </td></tr> <tr valign="top"><td><code>name</code></td> <td> <p>The base of the file name that the DLL should be moved to. The file name extension will depend on the operating system used</p> </td></tr> <tr valign="top"><td><code>directory</code></td> <td> <p>The directory that the DLL should be written to</p> </td></tr> <tr valign="top"><td><code>unload</code></td> <td> <p>In case the new path constructed from <code>name</code> and <code>directory</code> points to a loaded DLL, should we unload it?</p> </td></tr> <tr valign="top"><td><code>overwrite</code></td> <td> <p>In case there is a file at the new path constructed from <code>name</code> and <code>directory</code> should we overwrite that file?</p> </td></tr> <tr valign="top"><td><code>verbose</code></td> <td> <p>Should we print a message stating where the DLL was copied if the operation was successful?</p> </td></tr> <tr valign="top"><td><code>file</code></td> <td> <p>The file path for writing and reading the object generated by <code><a href="cfunction.html">cfunction</a></code>. Consider using a file name extension like <code>.rda</code> or <code>.RData</code> to indicate that this is a serialized R object. </p> </td></tr> <tr valign="top"><td><code>linenumbers</code></td> <td> <p>If <code>TRUE</code> all code lines will be numbered.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>May be used in future methods</p> </td></tr> </table> <h3>Details</h3> <p>If you move the DLL to a user defined location with <code>moveDLL</code>, this will keep an on-disk copy of the DLL which will prevent it from being lost at session termination - unless written to the session <code><a href="../../base/html/tempfile.html">tempdir</a></code>. Saving and reloading the <code>CFunc</code> object with standard tools like <code><a href="../../base/html/save.html">save</a></code> or <code><a href="../../base/html/readRDS.html">saveRDS</a></code> will still loose the pointer to the DLL. However, when the DLL has been moved using <code>moveDLL</code>, <code>CFunc</code> objects can be saved by <code>writeCFunc</code> and restored by <code>readCFunc</code>. </p> <h3>Value</h3> <p>Function <code>readDynLib</code> returns a <code>CFunc</code> object. </p> <p>Function <code>writeDynLib</code> returns the name of the <code>.CFunc</code> file that was created. </p> <h3>Note</h3> <ul> <li><p> The code of a <code>CFunc</code> or <code>CFuncList</code> object <code>x</code> can be extracted (rather than printed), using: </p> <p><code>x@code</code>. </p> </li> <li><p> To write the code to a file (here called <code>"fn"</code>), without the new-line character <code>"\n"</code>: </p> <p><code>write (strsplit(x, "\n")[[1]], file = "fn")</code> </p> </li></ul> <h3>Author(s)</h3> <p>Karline Soetaert and Johannes Ranke </p> <h3>See Also</h3> <p><code><a href="getDynLib.html">getDynLib</a></code> </p> <h3>Examples</h3> <pre> x <- as.numeric(1:10) n <- as.integer(10) code <- " integer i do 1 i=1, n(1) 1 x(i) = x(i)**3 " cubefn <- cfunction(signature(n="integer", x="numeric"), code, convention=".Fortran") code(cubefn) cubefn(n, x)$x ## Not run: # The following code is exempted from the automated tests of example code, as # it writes to the users home directory. # The following writes the DLL, e.g. cubefn.so on Linux/Unix or cubefn.dll # on Windows moveDLL(cubefn, name = "cubefn", directory = "~") path <- file.path("~", "cubefn.rda") writeCFunc(cubefn, path) rm(cubefn) # Now you can start a fresh R session and load the function library(inline) path <- file.path("~", "cubefn.rda") cfn <- readCFunc(path) cfn(3, 1:3)$x ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>inline</em> version 0.3.19 <a href="00Index.html">Index</a>]</div> </body></html>