我想问一下我们在gtext中输入后是否有对齐文本的方法。例如
x <- c(123.4, 5.6)
y <- c(1.2, 3.657)
z <- c(12345.6, 789.4)
df <- data.frame(x, y, z)
df.co <- capture.output(df) # get df as text
for (i in 1:length(df.co))
{
str.split <- strsplit(df.co, "\\s+") # split every line in its components
}
w3 <- gwindow()
gt3 <- gtext(container=w3)
for (i in 1:length(str.split)) # length(str.split)=3
{
for (j in 1:length(str.split[[i]])) # length(str.split[[i]])=2
{
str.split[[i]][[j]] <- paste(str.split[[i]][[j]],"\t",sep="",collapse="") # add tab to each component
}
str.split[[i]] <- paste(str.split[[i]], sep="", collapse="") # join to one line
insert(gt3, str.split[[i]])
}
这样我们就可以模仿 R 控制台。非常感谢,提前