Syntax highlighting for Xmin blogdown hugo theme - r

I have created a blog with the Xmin theme, but the code syntax is not hghlighted by default. So, I am following the instructions here to highlight the code.
Based on the instructions, I have put the following code:
In head_custom.html:
<link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
and in foot_custom.html:
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/r.min.js"></script>
<script>
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
</script>
In both files, I did not put <!DOCTYPE html> at the top because there was no instruction to do that.
After this, I saved the files and run blogdown:::serve_site(). But the syntax is not highlighted. What am I missing here?
Another question: If I want to highlight the syntax with different colors, what exactly do I need to copy paste? I have looked into https://cdnjs.com/libraries/highlight.js but do not understand how can I use it.
Edit:
Github repo: https://github.com/durraniu/rgems
Session Info:
R version 4.0.2 (2020-06-22) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252
attached base packages: [1] stats graphics grDevices utils datasets methods [7] base
loaded via a namespace (and not attached): [1] Rcpp_1.0.5 bookdown_0.20 digest_0.6.25 later_1.1.0.1 [5] mime_0.9 R6_2.4.1 jsonlite_1.7.0 magrittr_1.5 [9] evaluate_0.14 blogdown_0.20 rlang_0.4.7 promises_1.1.1 [13] rstudioapi_0.11 rmarkdown_2.3 tools_4.0.2 servr_0.18 [17] httpuv_1.5.4 xfun_0.16 yaml_2.2.1 compiler_4.0.2 [21] htmltools_0.5.0 knitr_1.29

The problem is that you have both layouts/partials/foot_custom.html and themes/hugo-xmin/layouts/partials/foot_custom.html. The former will override the latter (more info in Section 2.6 of the book).
To solve your problem, move the code from the latter foot_custom.html to the former.

Related

warning "using locale code page other than 65001 ("UTF-8") may cause problems" after R 4.2 update

I work with multiple locales/languages on Windows, and after my recent update to R 4.2, I keep seeing a warning " using locale code page other than 65001 ("UTF-8") may cause problems" whenever I try to set the system locale (and regardless of what language I try to set it to).
When I revert back to R 4.1.3, the warning doesn't appear.
Can anyone tell me what this warning means and whether there's anyway to get rid of it? Thanks!
> Sys.setlocale("LC_ALL","English")
[1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"
Warning message:
In Sys.setlocale("LC_ALL", "English") :
using locale code page other than 65001 ("UTF-8") may cause problems
> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
system code page: 65001
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] fansi_1.0.3 assertthat_0.2.1 dplyr_1.0.9 utf8_1.2.2
[5] crayon_1.5.1 grid_4.2.0 R6_2.5.1 DBI_1.1.2
[9] lifecycle_1.0.1 gtable_0.3.0 magrittr_2.0.3 scales_1.2.0
[13] ggplot2_3.3.6 pillar_1.7.0 rlang_1.0.2 cli_3.3.0
[17] generics_0.1.2 vctrs_0.4.1 ellipsis_0.3.2 glue_1.6.2
[21] purrr_0.3.4 munsell_0.5.0 compiler_4.2.0 pkgconfig_2.0.3
[25] colorspace_2.0-3 tidyselect_1.1.2 tibble_3.1.7
>

"Attempt to apply non-function" error when trying to write.csv

I'm just trying to export my data using write.csv like you'd expect
write.csv(df, "df.csv")
and I'm getting this error:
"Error in app$vspace(new_style$`margin-top` %||% 0) : attempt to apply non-function."
I'm not sure how to troubleshoot this/solve the issue! I double checked that my data is a standard class (it's a data.frame), but beyond that I'm at a loss because it looks like every other data.frame I've ever (successfully) exported. I'm not an experienced error-reader, but if it's helpful, the top line of the traceback is this:
clii__container_start(app, "span", class = funname)
I also did all the basics like quitting and restarting my R session, moving my working directory around, and checking if other data.frames can export -- they can, it's just this one that's stuck.
Here's the output for sessionInfo():
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] fansi_0.4.2 assertthat_0.2.1 utf8_1.2.1 crayon_1.5.1 dplyr_1.0.8 R6_2.5.1
[7] DBI_1.1.2 lifecycle_1.0.1 magrittr_2.0.1 pillar_1.7.0 rlang_1.0.2 cli_3.2.0
[13] rstudioapi_0.13 remotes_2.4.2 vctrs_0.3.8 generics_0.1.2 ellipsis_0.3.2 tools_4.1.0
[19] glue_1.4.2 purrr_0.3.4 xfun_0.30 compiler_4.1.0 pkgconfig_2.0.3 knitr_1.39
[25] tidyselect_1.1.2 tibble_3.1.2
and for rstudioapi::getVersion()
> rstudioapi::getVersion()
[1] ‘1.4.1106’

Error in if (num_colors <256) when importing csv files?

I recently updated to R 4.03 and since doing so I have had difficulty uploading csv files in R studio. This is true whether trying to import with code or when manually importing using the tab Environment -> "Import Dataset." The error message I receive is "Error in if (num_colors < 256) { : missing value where TRUE/FALSE needed."
Here is the code I am using:
library(readr)
df <- read_csv("df.csv")
Error in if (num_colors < 256) { : missing value where TRUE/FALSE needed`
I thought this may have something to do with the package "crayon" but loading this library does not seem to make a difference.
Furthermore, when I save "df.csv" as an excel file "df.xlsx" I am able to load the dataset without issue using the following code
library(readxl)
df <- read_excel(df.xlsx)
I don't encounter this problem when using R 4.0.2 on a different machine, so I suspect this issue may be related to the upgrade.
Any insights are appreciated.
Update:
Newish R user and I appreciate everyone's interest in this question. I believe the session is clean. Per Ben's request:
find("read_csv")
[1] "package:readr"
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_1.0.3 crayon_1.4.1 readxl_1.3.1 plyr_1.8.6 readr_1.4.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 rstudioapi_0.13 magrittr_2.0.1 hms_1.0.0 tidyselect_1.1.0 lattice_0.20-41 R6_2.5.0 rlang_0.4.10 fansi_0.4.2
[10] tools_4.0.3 grid_4.0.3 utf8_1.1.4 DBI_1.1.1 cli_2.3.0 ellipsis_0.3.1 assertthat_0.2.1 tibble_3.0.5 lifecycle_0.2.0
[19] Matrix_1.2-18 purrr_0.3.4 vctrs_0.3.6 glue_1.4.2 compiler_4.0.3 pillar_1.4.7 cellranger_1.1.0 generics_0.1.0 pkgconfig_2.0.3
I'd suggest updating RStudio to the latest version as well as R.
That did the trick for me.
Edit
In view of Ben's request below.
R version: 4.0.4;
RStudio version: 1.4.1103

Error: 'glmnet_softmax' is not an exported object from 'namespace:glmnet'

I am trying to use this tutorial https://github.com/wvictor14/planet#infer-ethnicity and get the following error message, even when using the test data provided:
pl_infer_ethnicity(pl_betas)
[1] "1860 of 1860 predictors present."
Loading required package: Matrix
Error: 'glmnet_softmax' is not an exported object from 'namespace:glmnet'
I've tried re-installing individual packages and running in a new version or R and get the same error. I believe this is related to other errors posted with a recent update in glmnet. Any tips on how to resolve?
sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Matrix_1.2-18 planet_0.1.0
loaded via a namespace (and not attached):
[1] lattice_0.20-38 codetools_0.2-16 glmnet_3.0-2 foreach_1.4.7
[5] crayon_1.3.4 grid_3.6.2 magrittr_1.5 pillar_1.4.2
[9] rlang_0.4.2 remotes_2.1.0 iterators_1.0.12 tools_3.6.2
[13] compiler_3.6.2 pkgconfig_2.0.3 shape_1.4.4 tibble_2.1.3
I don't know why it would have worked in the first place; the NEWS file for glmnet doesn't say anything one way or the other about glmnet_softmax (e.g., it does not say "glmnet_softmax is no longer exported" or anything like that ...)
In any case, this is a non-exported function from the glmnet package. It is referred to here in the tutorial code.
If you can change that line of code to refer to glmnet:::glmnet_softmax (i.e., three colons rather than two), that should suffice (::: allows you to access a non-exported function).

Can't get bookdown rmd_subdir ["dir"] to work

I tried to use the new rmd_subdir option in the _bookdown.yml by setting a list of subdirectories. I copied all files except the index.Rmd of a freshly created bookdown project in a folder called content. The following setting in the _bookdown.yml does work
rmd_subdir: = yes
However when I change the _bookdown.yml to the following only the index.Rmd is compiled.
_bookdown.yml
book_filename: "_tmp_rmd_subdir"
delete_merged_file: true
language:
ui:
chapter_name: "Chapter "
rmd_subdir: ["content"]
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
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 utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_0.12.15 bookdown_0.7 digest_0.6.14 rprojroot_1.3-2 backports_1.1.2
[6] magrittr_1.5 evaluate_0.10.1 stringi_1.1.6 rstudioapi_0.7 rmarkdown_1.9
[11] tools_3.4.3 stringr_1.3.0 tinytex_0.4 xfun_0.1 yaml_2.1.19
[16] rsconnect_0.8.5 compiler_3.4.3 htmltools_0.3.6 knitr_1.20
This should be fixed in the development version of bookdown. Please try
devtools::install_github('rstudio/bookdown')

Resources