daqana/tikzDevice

tikzCoord bug

amael-ls opened this issue · 1 comments

When trying to create a tikz plot, I could not use tikzCoord. Here is a minimum working example to reproduce my problem:

#### Minimum working example
## Load package
library(tikzDevice)

## Tikz plot
tikz("./test.tex", width = 3, height = 3)
tikzCoord(1, 0, "a")
tikzCoord(2, 1, "b")
tikzAnnotate("\\draw (a) -- (b);")
dev.off()

There is no error in the R console, but the coordinates are all (0,0) in the tex file:

% Created by tikzDevice version 0.12.3.1 on 2020-07-04 20:13:35
% !TEX encoding = UTF-8 Unicode
\coordinate (a) at (0,0);
\coordinate (b) at (0,0);
\draw (a) -- (b);

For information, I am using vscode and my rsession is:

> sessionInfo()
R version 4.0.1 (2020-06-06)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tikzDevice_0.12.3.1

loaded via a namespace (and not attached):
[1] compiler_4.0.1 tools_4.0.1    filehash_2.4-2 grid_4.0.1    

Using devtools::session_info():

> devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.1 (2020-06-06)
 os       macOS Catalina 10.15.5      
 system   x86_64, darwin17.0          
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/Toronto             
 date     2020-07-04Packages ───────────────────────────────────────────────────────────────────
 package     * version  date       lib source        
 assertthat    0.2.1    2019-03-21 [1] CRAN (R 4.0.0)
 backports     1.1.7    2020-05-13 [1] CRAN (R 4.0.0)
 callr         3.4.3    2020-03-28 [1] CRAN (R 4.0.0)
 cli           2.0.2    2020-02-28 [1] CRAN (R 4.0.0)
 crayon        1.3.4    2017-09-16 [1] CRAN (R 4.0.0)
 desc          1.2.0    2018-05-01 [1] CRAN (R 4.0.0)
 devtools    * 2.3.0    2020-04-10 [1] CRAN (R 4.0.0)
 digest        0.6.25   2020-02-23 [1] CRAN (R 4.0.0)
 ellipsis      0.3.1    2020-05-15 [1] CRAN (R 4.0.0)
 fansi         0.4.1    2020-01-08 [1] CRAN (R 4.0.0)
 filehash      2.4-2    2019-04-17 [1] CRAN (R 4.0.0)
 fs            1.4.1    2020-04-04 [1] CRAN (R 4.0.0)
 glue          1.4.1    2020-05-13 [1] CRAN (R 4.0.0)
 magrittr      1.5      2014-11-22 [1] CRAN (R 4.0.0)
 memoise       1.1.0    2017-04-21 [1] CRAN (R 4.0.0)
 pkgbuild      1.0.8    2020-05-07 [1] CRAN (R 4.0.0)
 pkgload       1.1.0    2020-05-29 [1] CRAN (R 4.0.0)
 prettyunits   1.1.1    2020-01-24 [1] CRAN (R 4.0.0)
 processx      3.4.2    2020-02-09 [1] CRAN (R 4.0.0)
 ps            1.3.3    2020-05-08 [1] CRAN (R 4.0.0)
 R6            2.4.1    2019-11-12 [1] CRAN (R 4.0.0)
 remotes       2.1.1    2020-02-15 [1] CRAN (R 4.0.0)
 rlang         0.4.6    2020-05-02 [1] CRAN (R 4.0.0)
 rprojroot     1.3-2    2018-01-03 [1] CRAN (R 4.0.0)
 sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 4.0.0)
 testthat      2.3.2    2020-03-02 [1] CRAN (R 4.0.0)
 tikzDevice  * 0.12.3.1 2020-06-30 [1] CRAN (R 4.0.1)
 usethis     * 1.6.1    2020-04-29 [1] CRAN (R 4.0.0)
 withr         2.2.0    2020-04-20 [1] CRAN (R 4.0.0)

[1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
> 

Well, it seems using this code fixes it (units = "device" is actually what is fixing it):

#### Minimum working example
## Load package
library(tikzDevice)

## Tikz plot
tikz("./test.tex", width = 3, height = 3)
tikzCoord(x = 1, y = 0, name = "a", units = "device")
tikzCoord(x = 2, y = 1, name = "b", units = "device")
tikzAnnotate("\\draw (a) -- (b);")
dev.off()

In the package, the default argument is units = "users", maybe there is something to check there...