Hi there, I've been trying to get R's TableOne package to work with Stata via Rcall. See details here to install R and Rcall. In addition to the details in the link, need to install TableOne. So in R, type:
I'm trying to output a CSV file following the directions here (under "Real Export Way")
Stata code:
The last line returns the Stata error:
...but the stata r(109) error seemingly keeps this from working. I'm wondering if folks have any suggestions about why this Stata error might be occurring and how I might address it. I suspect it has something to do with Rcall sending data back to Stata in the final line.
Thanks! Tim
Code:
install.packages("TableOne")
Stata code:
Code:
sysuse auto, clear // here's our dataset rcall vanilla: /// library("tableone") ; /// data<- st.data() ; /// rows <- c("price", "mpg", "rep78", "headroom", "trunk", "weight", "length") ; /// columns <-c("foreign") ; /// categorical <- c("rep78") ; /// medianiqr <- c("weight") ; /// table1 <-CreateTableOne(data=data, vars=rows, strata=columns, factorVars=categorical, addOverall = TRUE) ; /// output<-print(table1, nonnormal = medianiqr, missing=TRUE, quote=FALSE, noSpaces=TRUE, formatOptions = list(scientific = FALSE)) ;
string variables not allowed in varlist;I would need to add a triple slash and then one more line to get a CSV output of above, if I didn't get that error. Final line:
Overall is a string variable
r(109);
Code:
write.csv(output, file = "table1.csv") ;
Thanks! Tim
Comment