# Adapting output columns to result table row count - Some tips if you see this message, and a question about locating documentation.

Adapting output columns to result table row count - Some tips if you see this message, and a question about locating documentation

I'm just getting started with R, and worked through the example of a temperature converter that takes value from one column, and outputs the converted value to another column

http://stn.spotfire.com/spotfire_client_help/df/df_details_on_register_d...

All looks very straightforward, but after some time trying playing with the calculation, it's apparent that some additional (possibly undocumented?) knowledge is required to adapt this capability to real world scenarios: In particular, you might suppose that the calculation is running for every row in the table, and generating an output along these lines:

# Define the function:

myFunction <- function(inputColumn) {

Return "SomeText"

}

# Run the function to produce the output:

outputColumn <- myFunction(inputColumn);

Unfortunately this does not work the function above returns one row of data and Spotfire complains with a message headed 'Adapting output columns to result table row count'

It seems that instead Spotfire is passing the entire column to R as a vector, and is expecting a return vector containing exactly the right number of rows of data to populate the new column.

To get the required result, something along these lines is needed (remember, I'm just starting in R, so appreciate there will probably be better ways to do this):

# Define the function:

myFunction <- function(inputColumn) {

newColumn <- 1:length(inputColumn) #create a vector of rows

for(i in 1:length(inputColumn)) {

newColumn[i] <- "SomeText"

}

return(newColumn)

}

# Run the function to produce the output:

outputColumn <- myFunction(inputColumn);

My point of posting is twofold

First, if anyone hits the 'Adapting output columns to result table row count message', this may save them some time and frustration

Second, I spent a fair amount of time trying to get this to work, and did not find much documentation or references across the web to help; in the end I had to work it out by brute force and persistence; Don't get me wrong, I can see some big advantages to being able to work with the entire rowset within the function; but where would this kind of thing be documented?

Can anyone flag if I missed some documentation, or a source of this type of information? Thanks for any help you can offer