Examples for <code language_="r">

Usage examples to leverage the new language_="r" functionality in the <code> tag.


The <code> tag now supports language_="r", allowing 1010data to interface with this popular statistics package from within your macro code. See <code> in the 1010data Reference Manual for more information.

When using the <code> tag, it is necessary to put the R functions and related operations inside of a CDATA tag.

Note: Your account must be specifically enabled to make use of the R language.


The following example creates a new worksheet with the columns 'state' and 'elev'. The new worksheet is a subset of rows and columns.

<base table="pub.demo.weather.stations">
<code language_="r">
    #Create a new worksheet with the columns 'state' and 'elev'.
    #The new worksheet is a subset of rows and columns.
    #The R objects 'table' and 'ops' automatically exist in the R session.
    n <- Rows(ops,table)                          #get number of rows
    cmd <- ColsMetaData(ops,table)                #get meta-data
    cols <- c('state','elev')
    cols.ind <- which(ColNames(cmd) %in% cols)
    cmd2 <- SliceMetaData(cmd,cols.ind)           #subset meta-data
    dat <- Data(ops,table,10:n,cols)              #get data
    ops <- ReBase(dat,cmd2)                       #re-base and assign to new value to ops.

The following example tests 4 columns for normality:

<base table="mdb_regression_test_folder.stations"/>
<code language_="r">
a <- function(ops,table){
  if((N <- Rows(ops,table)) > 1000000) stop('too much data')
  d <- Data(ops,table)
  test.cols <- c('lat','lon','elev','anht')
  #run shapiro tests and rbind together data.frames
  shapiro.results <- do.call("rbind",
                               r <- shapiro.test(x)
  shapiro.results$name <-row.names(shapiro.results)
  #run KS tests and rbind results
  ks.results <- do.call("rbind",
                          r <- ks.test(scale(x),"pnorm")
  ks.results$name <- row.names(ks.results)
  #rbind shapiro and KS results
  res <- rbind(shapiro.results,ks.results)
  ops <- ReBase(res)}
ops <- a(ops,table)
<willbe name="is_normal" value="p_val>0.05"/>