rkrug / plantuml

R package to build UML graphs using plantuml
https://rkrug.github.io/plantuml/index.html
GNU General Public License v3.0
76 stars 8 forks source link

R plantuml package produce error when the label contains new line while planttext.com can display it fine. #21

Closed wei-wu-nyc closed 1 year ago

wei-wu-nyc commented 2 years ago

I am relatively new to plantuml and your package. So I may be reporting a known issue. We encountered some issue in our project that used plantuml package. I isolated into the following reproducible simple example. The following simple plantuml code works fine in planttext.com: @startuml a:A,\nAA b:B,\nBB a --> b @enduml However, if I do this in R plantuml package with: plot(plantuml(' @startuml a:A,\nAA b:B,\nBB a --> b @enduml '))

It produces errors: ERROR 2 Syntax Error? Some diagram description contains errors Error in polypath(trans(pathX, pathY), rule = switch(p@rule, nonzero = "winding", : unable to allocate memory (in GPath) Notice the embedded newline character in the description fields for a and b. If we take out the newline, the diagram works. plot(plantuml(' @startuml a:A,AA b:B,BB a --> b @enduml '))

I am not sure if it is a problem with the R package or the plantuml.jar that it uses. Any suggestions for workaround or fixes?

rkrug commented 1 year ago

I looked at this with version 0.6.5, and the error is different, but still there.

It is caused by the escaping of the text. The first one is, as the R string:

(a) @startuml\na:A,\\nAA\nb:B,\\nBB\na --> b\n@enduml (note the double \\)

and the second one

(b) \n@startuml\na:A,\nAA\nb:B,\nBB\na --> b\n@enduml\n

In the case of (b), the \n are interpreted as line breaks, and the \\n is send to plantuml as the character \n, i.e. as intended as a line break in the plantuml text.

In the case of (b), all \n are interpreted as line breaks in R, therefore resulting in invalid plantuml code.

So: if you want to have line breaks in the plantuml labels, you have to use \\n in the case of using plot(). I do not see a way that this can be avoided.

Thanks for this report, it is very useful.

Thanks,

Rainer