rr-markdowndynamic-tables

How to create dynamic table heading in R Markdown


I would like to create a dynamic table heading, which updates based on the number of regression coefficients (k,a,b,c,d,..,n,n+1) and regression equations(U4ST,U4STAW,...n,n+1).

Is it possible to use the "Y" and "X" variables provided in the Code below to make the table dynamic so that it can change if the length of the X and Y variables decrease or increase? Thank you kindly.

txt = "Base Condition,k,a,b,c
U4ST,0.29,-3.12,0.27,0.16
U4STAW,1.24,-12.37,1.22,0.27
U3ST,3.18,-5.35,0.34,0.28
U4SG,0.38,-3.47,0.42,0.14
SHS U4SG,0.38,-3.47,0.42,0.14
SHS U4ST,0.29,-3.12,0.27,0.16"
txtTable=TextToTable(txt, sep=",", dimnames=c("Index","Safety Analyst SPF  Coefficients"), header=TRUE)


Y=length(txtTable[,1])
X=length(txtTable[2,])-1

#table
txtTable %>% kable(align= 'c', caption = "Information System X Regression Coefficients for Y Base Condition regression equations")```

Solution

  • When I understand the question right, the solution should just be the `paste? function:

    txtTable %>% kable(align= 'c', caption = paste0("Information System ",X, " Regression Coefficients for ", Y," Base Condition regression equations"))