Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when knitting after update #108

Closed
petermacp opened this issue Apr 9, 2020 · 7 comments
Closed

Error when knitting after update #108

petermacp opened this issue Apr 9, 2020 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@petermacp
Copy link

I had a cv set up and working beautifully based on the hyndman template.

However, having updated a bunch of packages (now on vitae v0.2.1), the Rmarkdown file still runs fine, but I get the following error message when I attempt to knit to pdf.

Any suggestions gratefully received.

Quitting from lines 117-123 (PM_CV.Rmd) 
Error: Lossy cast from `value` <character> to `x` <logical>.
* Locations: 1
Backtrace:
     x
  1. +-rmarkdown::render(...)
  2. | \-knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  3. |   \-knitr:::process_file(text, output)
  4. |     +-base::withCallingHandlers(...)
  5. |     +-knitr:::process_group(group)
  6. |     \-knitr:::process_group.block(group)
  7. |       \-knitr:::call_block(x)
  8. |         \-knitr:::block_exec(params)
  9. |           +-knitr:::in_dir(...)
 10. |           \-knitr:::evaluate(...)
 11. |             \-evaluate::evaluate(...)
 12. |               \-evaluate:::evaluate_call(...)
 13. |                 +-base:::handle(...)
 14. |                 +-base::withCallingHandlers(...)
 15. |                 +-base::withVisible(value_fun(ev$value, ev$visible))
 16. |                 \-knitr:::value_fun(ev$value, ev$visible)
 17. |                   \-knitr:::fun(x, options = options)
 18. |                     +-base::withVisible(knit_print(
Execution halted

@jimjunker1
Copy link

jimjunker1 commented Apr 9, 2020

I am having a similar issue when knitting a document. As far as I can tell it is originating with detailed_entries(). When I knit the document without detailed_entries() the document renders with no error, but this error is thrown when it is included.
Here is a simple example and error (please excuse the poor formatting)

---
title: "Untitled"
date: "4/8/2020"
output:  html_document
---
'```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, 
                      warning = FALSE,
                      message = FALSE)

library(vitae)
library(tidyverse)
'```
'```{r get data, include=FALSE}
## Skills
skills <- tibble::tribble(
  ~a, ~b,
  "a1","b1",
  "a2","b2",
  "a3","b3"
)
'```
'```{r}
 skills %>%
  detailed_entries(what = a, with = b)
'```

This throws the similar error to above:

Error: Lossy cast from 'value' <character> to 'x' <logical>.
* Locations: 1
Backtrace:
     x
  1. +-rmarkdown::render(...)
  2. | \-knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  3. |   \-knitr:::process_file(text, output)
  4. |     +-base::withCallingHandlers(...)
  5. |     +-knitr:::process_group(group)
  6. |     \-knitr:::process_group.block(group)
  7. |       \-knitr:::call_block(x)
  8. |         \-knitr:::block_exec(params)
  9. |           +-knitr:::in_dir(...)
 10. |           \-knitr:::evaluate(...)
 11. |             \-evaluate::evaluate(...)
 12. |               \-evaluate:::evaluate_call(...)
 13. |                 +-base:::handle(...)
 14. |                 +-base::withCallingHandlers(...)
 15. |                 +-base::withVisible(value_fun(ev$value, ev$visible))
 16. |                 \-knitr:::value_fun(ev$value, ev$visible)
 17. |                   \-knitr:::fun(x, options = options)
 18. |                     +-base::withVisible(knit_print(

Execution halted

Some session details:

sessionInfo('vitae')
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:

attached base packages:
character(0)

other attached packages:
[1] vitae_0.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6     grDevices_3.6.1  fansi_0.4.1      digest_0.6.25    crayon_1.3.4    
 [6] assertthat_0.2.1 lifecycle_0.2.0  magrittr_1.5     evaluate_0.14    datasets_3.6.1  
[11] pillar_1.4.3     rlang_0.4.5      utils_3.6.1      cli_2.0.2        rstudioapi_0.11 
[16] vctrs_0.2.4      graphics_3.6.1   ellipsis_0.3.0   rmarkdown_2.1    base_3.6.1      
[21] tools_3.6.1      glue_1.4.0       xfun_0.12        yaml_2.2.1       compiler_3.6.1  
[26] pkgconfig_2.0.3  stats_3.6.1      htmltools_0.4.0  knitr_1.28       methods_3.6.1   
[31] tibble_3.0.0    

@johnaeanderson
Copy link

For now, revert to the previous version of tibble using this code to get things working again.

install_version("tibble", version = "2.1.3", repos = "http://cran.us.r-project.org")`

@mitchelloharawild mitchelloharawild self-assigned this Apr 15, 2020
@mitchelloharawild mitchelloharawild added the bug Something isn't working label Apr 15, 2020
@mitchelloharawild
Copy link
Owner

Reprex:

library(vitae)
#> 
#> Attaching package: 'vitae'
#> The following object is masked from 'package:stats':
#> 
#>     filter
skills <- tibble::tribble(
  ~a, ~b,
  "a1","b1",
  "a2","b2",
  "a3","b3"
)
skills %>%
  detailed_entries(what = a, with = b) %>% 
  knitr::knit_print()
#> Error: Can't convert from <character> to <logical> due to loss of precision.
#> * Locations: 1

Created on 2020-04-15 by the reprex package (v0.3.0)

@mitchelloharawild
Copy link
Owner

Should work better now, thanks!

@masumistadler
Copy link

masumistadler commented Dec 4, 2020

Hi, I'm having a similar issue. Has there been an update on this bug?
I installed tibble version 2.1.3 and tried the code, but the error still appears. I do get a different error though:

# Borrowing example code from jimjunker1
skills <- tibble::tribble(
  ~a, ~b,
  "a1","b1",
  "a2","b2",
  "a3","b3"
)
 skills %>%
  detailed_entries(what = a, with = b) %>%
   knitr::knit_print(skills)

Traceback from markdown:

Error in entry_format_functions$format$detailed(protect_tex_input(x$what), : attempt to apply non-function
5.
structure(x, class = "knit_asis", knit_meta = meta, knit_cacheable = cacheable)
4.
knitr::asis_output(entry_format_functions$format$detailed(protect_tex_input(x$what), protect_tex_input(x$when), protect_tex_input(x$with), protect_tex_input(x$where), lapply(x$why, protect_tex_input)))
3.
knit_print.vitae_detailed(., skills)
2.
knitr::knit_print(., skills)
1.
skills %>% detailed_entries(what = a, with = b) %>% knitr::knit_print(skills)

The same error happens with brief_entries.

SessionInfo (ran it here again after re-installing tibble 3.0.4):

R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] vitae_0.3.0.9000 dplyr_1.0.2      tibble_3.0.4    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        pillar_1.4.7      compiler_4.0.3    plyr_1.8.6       
 [5] R.methodsS3_1.8.1 R.utils_2.10.1    tools_4.0.3       digest_0.6.27    
 [9] jsonlite_1.7.1    lubridate_1.7.9.2 evaluate_0.14     lifecycle_0.2.0  
[13] R.cache_0.14.0    pkgconfig_2.0.3   rlang_0.4.9       cli_2.2.0        
[17] rstudioapi_0.13   yaml_2.2.1        xfun_0.19         RefManageR_1.3.0 
[21] httr_1.4.2        stringr_1.4.0     xml2_1.3.2        knitr_1.30       
[25] generics_0.1.0    vctrs_0.3.5       tidyselect_1.1.0  glue_1.4.2       
[29] R6_2.5.0          fansi_0.4.1       rmarkdown_2.5     purrr_0.3.4      
[33] scholar_0.1.7     magrittr_2.0.1    ellipsis_0.3.1    htmltools_0.5.0  
[37] assertthat_0.2.1  rvest_0.3.6       stringi_1.5.3     crayon_1.3.4     
[41] R.oo_1.24.0 

@lunafazio
Copy link

lunafazio commented Dec 27, 2020

I've traced the error back to this line.

It seems the way in which entries are formatted has changed and your output must first be passed through one of the cv_document wrapper functions (see ?vitae::awesomecv). Without that step, set_entry_formats won't be called and entry_format_functions$format$detailed will be NULL instead of a function that formats the text you passed it.

This should be fixed by calling one of the aforementioned wrappers in the output section of your YAML, though I'm not sure how that will interact with older custom styles (my case). I'll update when I get mine to work.


Okay, so in the last working version I had used a custom function for the output like so:

output: (function (...) {;template <- here::here("cv-template.tex");vitae::cv_document(..., template = template, citation_package = "biblatex",latex_engine = "xelatex")})

I tried out simply using

output: vitae::awesomecv

which worked just fine. But I want to use my own variation of the style, so I looked inside vitae::awesomecv and made a custom function that calls my own template, cv-template.tex:

output: (function (..., latex_engine = "xelatex") {; template <- here::here("cv-template.tex"); vitae:::set_entry_formats(vitae:::awesome_cv_entries); vitae:::copy_supporting_files("awesomecv"); vitae::cv_document(..., template = template, latex_engine = latex_engine)})

The spacing is off compared to the previous version, but I suppose a fix will just take some fiddling with the template files and functions. Hopefully the above will be enough to resolve the problem for anyone else that stumbles upon it.

Finally, worth mentioning I did revert to 2.1.3 tibble but also went back to R 3.6.3, unsure if this might work in later versions. Will update later if it does.


Okay, final update. Got my custom template function working on R 4.0.2, though it still required going back to tibble 2.1.3. Using pandoc 2.11.3.1, FYI.

I'm also using renv now to properly keep track of all the library versions and suggest anyone reading this does the same so they don't accidentally break their CV updating workflow while updating other packages.

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] vitae_0.3.0  tibble_2.1.3

loaded via a namespace (and not attached):
 [1] crayon_1.3.4     dplyr_1.0.2      R6_2.5.0         lifecycle_0.2.0  magrittr_2.0.1   pillar_1.4.7    
 [7] rlang_0.4.9      renv_0.12.3      rstudioapi_0.13  vctrs_0.3.5      generics_0.1.0   ellipsis_0.3.1  
[13] tools_4.0.2      glue_1.4.2       purrr_0.3.4      xfun_0.19        compiler_4.0.2   pkgconfig_2.0.3 
[19] knitr_1.30       tidyselect_1.1.0

@dendroica
Copy link

Thank you @lunafazio your solution worked for me for awhile, and now is no longer working under these versions:

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/New_York
tzcode source: system (glibc)

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

loaded via a namespace (and not attached):
 [1] compiler_4.4.1    fastmap_1.2.0     cli_3.6.3         htmltools_0.5.8.1 tools_4.4.1       rstudioapi_0.17.1 yaml_2.3.10       rmarkdown_2.29    knitr_1.49       
[10] xfun_0.49         digest_0.6.37     rlang_1.1.4       evaluate_1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants