TERR error when stacking columns in data function using reshape


I have found a strange error in TERR when I attempt to stack columns in a data function using base R function "reshape", and I cannot reproduce the error when I try to run the same function in RStudio using standard R. Note, that I am not using any external packages for this. I have a very simple table in wide format with only two rows (see attachment "wide_table_image.pdf"), and I want to stack the last three columns into a tall format and the resulting table will have six rows. I need to do the stack operation in a data function in this case, so I cannot use the Spotfire built-in stack functions.

I have attached the simple table in .csv format (attachment: wide_data.csv) that I can import into Tibco Spotfire to reproduce the error. I have also attached the code for my data function to this message (attachment: data_function.R.txt), as well as some screen-shots showing the data function parameters (attachment: data_function_parameters.pdf).  In addition, I have also attached the corresponding version of the script that I run in RStudio (stack_data.R.txt) and the wide data table in RData format (wide_data.zip --> contains wide_data.RData). The path in line 2 of the R script would of course need to be edited to point to the location of wide_data.RData.

The function call that generates the TERR error in my script is:

#this is the line that fails in TERR but works fine in RStudio with standard R
tdata <- reshape(wdata, varying=cnames_values, timevar=k_param,
                 v.names=k_data, times=cnames_values, direction="long",

The full error message is:

Could not execute function call.
TIBCO Enterprise Runtime for R returned an error: 'Error in .reshape.unpaste(varying, split) : Could not unpaste text into non-null components'.
   at Spotfire.Dxp.Data.DataFunctions.Executors.LocalFunctionClient.OnExecuting(FunctionClient funcClient)
   at Spotfire.Dxp.Data.DataFunctions.Executors.AbstractFunctionClient.<RunFunction>d__0.MoveNext()
   at Spotfire.Dxp.Data.DataFunctions.Executors.SPlusFunctionExecutor.<ExecuteFunction>d__0.MoveNext()
   at Spotfire.Dxp.Data.DataFunctions.DataFunctionExecutorService.<ExecuteFunction>d__6.MoveNext()


I am using Spotfire 6.5.3 HF-017.

I have also attached a screenshot of the succesful output when running the function in RStudio (RStudio_succesful_output.pdf). This shows the desired output table format that I am looking for in my data function (tdata).

I haven't been able to find any other user examples of the base reshape function in TERR, and any help on this would be much appreciated!