Blame | Last modification | View Log | Download | RSS feed
<?xml version="1.0"?><article xmlns:r='http://www.r-project.org'><para>This is a very simple example of using an XML file to create annotatedR code that defines some functions and also has a "main" scriptin the style of Python scripts that can be loaded or run.<r:function id="myFun">myFun =function(n){sum(sample(1:10, n, replace = TRUE))}</r:function></para><para>We define a second functionand we use an id attribute "B"eventhough this is not the name of the function.Note also that we use the CDATA constructto specify the content of the node asthe code contains characters < and >and & that are special to XML.<r:function id="B"><![CDATA[inRect <-function(pos, x, y, w, h){pos[1] >= x & pos[2] >= y & pos[1] <= x + w & pos[2] <= y + h}]]></r:function>We only need to surround this code with the start and end of the CDATAdelimeters and we don't have to escape the individual characters.This makes it easier to cut and paste the code directly into anotherapplication.</para><para><r:code>inRect(c(10, 10), 3, 4, 10, 10)myFun()</r:code></para></article>