0

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.

Marina
  • 369
  • 3
  • 9
  • 1
    `paste("One", collapse = "\\n")` and the similar expressions below will completely ignore the `collapse` argument, because `"One"` is length 1. `collapse` is put between elements when pasting longer vectors. I can't believe this ever worked for you; you should check your old scripts to find what they really had. – user2554330 Dec 02 '20 at 17:14

1 Answers1

0

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")
Marina
  • 369
  • 3
  • 9