R tkinsert does not recognize "\\n"

81 Views Asked by At

New example

I'm updating the question after user2554330's comment. Since I updated my R version, the tkinsert function from package tcltk does not recognize the flag "\n". How can I write different lines?

New example. This is a real example that used to work, writing 3 lines of asterisks and 3 empty lines:

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", paste("\\n\\n"))
tcltk::tkinsert(txt.w , "end", paste("\\n\\n"))
tcltk::tkinsert(txt.w , "end", paste("\\n\\n"))

Now I get this (I replace multiple asterisks by dots, otherwise the message is not shown properly).

"...\n**************...\n*****...***\n\n\n\n\n\n\n"

Instead of three lines of asterisks and three empty lines.

Actually I could have written this, but the result is the same.

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", "\\n\\n")
tcltk::tkinsert(txt.w , "end", "\\n\\n")
tcltk::tkinsert(txt.w , "end", "\\n\\n")

With this other version the result is still the same

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", "\\n")
tcltk::tkinsert(txt.w , "end", "\\n")
tcltk::tkinsert(txt.w , "end", "\\n")

Old example

Since I updated my R version, the tkinsert function from package tcltk does not recognize the flag "\n". I want to write different lines, but "\n" does not work and neither do other options (I get all the numbers likes this: OneTwoThreeFourFiveSix.

tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
tcltk::tkinsert(txt.w, "end", paste("One", collapse = "\\n"))
tcltk::tkinsert(txt.w, "end", paste("Two", collapse = "\n"))
tcltk::tkinsert(txt.w, "end", paste("Three", collapse = "\n\r"))
tcltk::tkinsert(txt.w, "end", paste("Four", collapse = "\t"))
tcltk::tkinsert(txt.w, "end", paste("Five", collapse = "\\t"))
tcltk::tkinsert(txt.w, "end", paste("Six", collapse = "\r\n"))

I'm working on Windows.

1

There are 1 best solutions below

0
On

This works now (at least on Windows):

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))

endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w, "end", endL, collapse = "\n")
tcltk::tkinsert(txt.w, "end", endL, collapse = "\n")
tcltk::tkinsert(txt.w, "end", endL, collapse = "\n")
tcltk::tkinsert(txt.w, "end", "\n\n")
tcltk::tkinsert(txt.w, "end", "\n\n")
tcltk::tkinsert(txt.w, "end", "\n\n")

This works too:

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))

endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w, "end", endL)
tcltk::tkinsert(txt.w, "end", "\n")
tcltk::tkinsert(txt.w, "end", endL)
tcltk::tkinsert(txt.w, "end", "\n")
tcltk::tkinsert(txt.w, "end", endL)
tcltk::tkinsert(txt.w, "end", "\n")
tcltk::tkinsert(txt.w, "end", "\n\n")
tcltk::tkinsert(txt.w, "end", "\n\n")
tcltk::tkinsert(txt.w, "end", "\n\n")

Old example now working:

tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
tcltk::tkinsert(txt.w, "end", "One", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Two", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Three", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Four", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Five", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Six", collapse = "\n")