I have successfully used save_kable() from kableExtra to export latex tables into *.png before. However, after updating R to the version 4.0.2, save_kable always ends with R fatal error (no specific error message is shown, the session is just aborted). I installed a clean version o R 3.6.3 and everything works fine again.
Next, I re-installed MikTEX, but this does not seem to be the problem because R Markdown can knit a .pdf file without an issue (in the 4.0.2 version). Also, using save_kable with "html" options works fine and exports the table into .png. The problem seems to be specific for latex.
Looking at sessionInfo(), the only difference is that R 3.6.3 automatically loads the 'magick' package, while R 4.0.2 does not. However, loading the magick package manually in the latter R version does not solve the problem. Then, of course, the sessions differ in the "compiler" package versions. Maybe this is the source of the problem?
Any help would be much appreciated. The problem can be reproduced with minimal code such as
kable(mtcars, "latex") %>% save_kable("test.png")
Here is the sessionInfo
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
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
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
other attached packages:
[1] magick_2.4.0 kableExtra_1.1.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 rstudioapi_0.11 knitr_1.29 xml2_1.3.2 magrittr_1.5
[6] hms_0.5.3 rvest_0.3.5 munsell_0.5.0 viridisLite_0.3.0 colorspace_1.4-1
[11] R6_2.4.1 rlang_0.4.7 stringr_1.4.0 httr_1.4.1 tools_4.0.2
[16] webshot_0.5.2 xfun_0.15 htmltools_0.5.0 ellipsis_0.3.1 digest_0.6.25
[21] tibble_3.0.3 lifecycle_0.2.0 crayon_1.3.4 readr_1.3.1 vctrs_0.3.2
[26] glue_1.4.1 evaluate_0.14 rmarkdown_2.3 stringi_1.4.6 compiler_4.0.2
[31] pillar_1.4.6 scales_1.1.1 pkgconfig_2.0.3
This seems to be a windows specific problem. I actually just asked a recent question here
kableExtra HTML styling in Rmarkdown and kable_save()
Some of the things I have seen mentioned as potential fixes are listed there such as updating ghostscript, not using tinytext, updating some latex packages including 'standalone', and editing the policy.xls document in ImageMagick ImageMagick security policy 'PDF' blocking conversion.
None of these worked for me and I get the same crashing issues the second I try to kable_save a latex format into png. However, some other Windows users have found success with the steps above so maybe try that out and see how it goes.
Related
I have ggplot2 3.4.0 installed on Ubuntu 22.04, but for some reasons I would like to use older version ggplot2 3.3.6.
library(ggplot2, lib.loc="~/R/ggplot336/")
I worked fine when I started with a clean script file. However, when I use an existing script file like:
library(ggplot2, lib.loc="~/R/ggplot336/")
ggimage::geom_image()
I got the following error massage:
Error in value[3L] :
Package ‘ggplot2’ version 3.4.0 cannot be unloaded:
Error in unloadNamespace(package) : namespace ‘ggplot2’ is imported by ‘ggfun’, ‘ggplotify’, ‘ggimage’ so cannot be unloaded
Edit
Fresh start Rstudio
Open my R script file with following 3 lines:
sessionInfo()
library(ggplot2, lib.loc="~/R/ggplot336/")
ggimage::geom_image()
When I run the first line, sessionInfo() before doing anything else. We can see ggplot2_3.4.0 there. Could this be a Rstudio feature or an issue?
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
locale:
[1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C LC_TIME=en_AU.UTF-8
[4] LC_COLLATE=en_AU.UTF-8 LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8
[7] LC_PAPER=en_AU.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 highr_0.9 pillar_1.8.1 compiler_4.2.2
[5] R.utils_2.12.2 R.methodsS3_1.8.2 yulab.utils_0.0.5 tools_4.2.2
[9] digest_0.6.30 evaluate_0.18 jsonlite_1.8.3 lifecycle_1.0.3
[13] tibble_3.1.8 gtable_0.3.1 ggimage_0.3.1 R.cache_0.16.0
[17] pkgconfig_2.0.3 rlang_1.0.6 reprex_2.0.2 DBI_1.1.3
[21] cli_3.4.1 ggplotify_0.1.0 rstudioapi_0.14 magick_2.7.3
[25] yaml_2.3.6 xfun_0.35 fastmap_1.1.0 knitr_1.41
[29] withr_2.5.0 dplyr_1.0.10 styler_1.8.1 generics_0.1.3
[33] vctrs_0.5.1 fs_1.5.2 gridGraphics_0.5-1 grid_4.2.2
[37] tidyselect_1.2.0 glue_1.6.2 R6_2.5.1 processx_3.8.0
[41] fansi_1.0.3 rmarkdown_2.18 clipr_0.8.0 callr_3.7.3
[45] ggplot2_3.4.0 purrr_0.3.5 magrittr_2.0.3 ps_1.7.2
[49] htmltools_0.5.3 scales_1.2.1 assertthat_0.2.1 colorspace_2.0-3
[53] utf8_1.2.2 munsell_0.5.0 ggfun_0.0.9 R.oo_1.25.0
It looks like R studio is loading in all of the previous libraries from a previous session. Maybe something leftover in .RData or .Rhistory. A fresh start of R should have far few loaded libraries.
Here is my fresh start:
sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.6.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/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
loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2
In Rstudio's preference you should see this screen:
I would try unchecking all of the boxes and then quit and restart Rstudio to see if that clears up the problem.
After some experiments, I kind of worked out the problem. Since this has consumed so much time of my time, I thought this could be helpful to others.
The problem is :: (double colon) with packages using ggplot2, such as ggimage in my example. It appears that RStudio automatically load some dependent packages when a script file is open. One way to fix this problem for my work now is to remove ::, but use library() then function (geom_image) instead.
This fixed my problem but I still don't understand why RStudio behaves this way.
If :: (double colon) is necessary, comment lines containing ::, then after loading older version of ggplot2, uncomment those lines. A little awkward, but it works for me.
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
thanks for checking out my very first post. please bear with my formatting.
Issue summary: I have been using tdplyr to access teradata database with no issue until I tested another package called dplyr.teradata for potential performance enhancement. However I can no longer connect to the database due to the following error messages:
Error: package or namespace load failed for 'tdplyr':.onLoad failed
in loadNamespace() for 'tdplyr', details:
call: parent.env(from)
error: argument is not an environment
so I deleted the dplyr.teradata package, thought that would allow my original tdplyr to work, but I still get the same error message above. then I deleted the tdplyr package without backup, trying to reinstall using the original script below:
install.packages('tdplyr',repos=c('https://teradata-download.s3.amazonaws.com','https://cloud.r-
project.org'))
but fail to install because of the same error again. Hope someone could advise on fix.
My sessioninfo is below:
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)
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
other attached packages:
[1] rlang_0.4.10 teradatasql_17.0.0.8 odbc_1.3.0 dplyr_1.0.2
[5] dbplyr_2.0.0 digest_0.6.27 DBI_1.1.0 hms_0.5.3
[9] bit64_4.0.5 bit_4.0.4
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 rstudioapi_0.13 magrittr_1.5 tidyselect_1.1.0 R6_2.4.1
[6] blob_1.2.1 tools_4.0.3 xfun_0.20 tinytex_0.28 ellipsis_0.3.1
[11] assertthat_0.2.1 tibble_3.0.4 lifecycle_0.2.0 crayon_1.3.4 zip_2.1.1
[16] purrr_0.3.4 vctrs_0.3.6 glue_1.4.2 openxlsx_4.2.3 stringi_1.5.3
[21] compiler_4.0.3 pillar_1.4.6 generics_0.0.2 pkgconfig_2.0.3
found the answer myself. Pasting the answer below.
The Teradata R package is incompatible with dbplyr v2.0.0 and its later versions, which introduced some breaking changes. To use tdplyr, the version of dbplyr package must be v1.4.4. tdplyr should be installed using the following commands from your Terminal (for Linux and Mac) or Command Prompt (for Windows), till a new version that is compatible with dbplyr v2.0.0 and its later versions is released:
Install dbplyr v1.4.4 first. There are various ways to install a specific version of a R package. Teradata recommends using the following command:
Rscript -e "remotes::install_version('dbplyr',version='1.4.4',repos='https://cloud.r-project.org')"
Note: To run this above command, the R package remotes should be present on the client machine.
Next to download and install tdplyr and dependencies automatically, if minimum required versions are not met, specify the Teradata R package repository and CRAN in the repos argument for install.packages.
Rscript -e "install.packages('tdplyr',repos=c('https://teradata-download.s3.amazonaws.com','https://cloud.r-project.org'))"
Every time I run into an error while knitting a script that stops execution, RStudio behaves in a weird way: In the R markdown tab it reads in red that the execution is stopped but in the R markdown tab I see the continuing progress circle still moving, suggesting that knitting is still ongoing. Also on the right hand I see that "stop" sign but clicking on it also does not stop executing. I can still write text in the script but I can no longer execute the script and can also not kick off a new knitting attempt.
The only way of going back to normal is top close Rstudio and re-start it. That means, everytime I run into any kind of error while knitting I have to restart Rstudio. This does not occur on my private PC with the same scripts.
I have installed a new version of Rstudio (the new 1.4 Preview) and I have re-installed R Markdown. Do you have any tips?
edit:
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] rmarkdown_2.5
loaded via a namespace (and not attached):
[1] rstudioapi_0.13 knitr_1.30 magrittr_2.0.1 tidyselect_1.1.0
[5] R6_2.5.0 rlang_0.4.9 dplyr_1.0.2 tools_4.0.3
[9] xfun_0.19 pacman_0.5.1 htmltools_0.5.0 ellipsis_0.3.1
[13] yaml_2.2.1 digest_0.6.27 tibble_3.0.4 lifecycle_0.2.0
[17] crayon_1.3.4 purrr_0.3.4 tidyr_1.1.2 vctrs_0.3.5
[21] clisymbols_1.2.0 glue_1.4.2 evaluate_0.14 compiler_4.0.3
[25] pillar_1.4.7 generics_0.1.0 pkgconfig_2.0.3 tidylog_1.0.2
To elaborate on the title,
I am using rstudio making an rmarkdown file that contains both r and python code. My configuration is below:
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C 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_1.0.4.6 rstudioapi_0.11 knitr_1.28 magrittr_1.5 rappdirs_0.3.1 tidyselect_1.0.0
[7] munsell_0.5.0 lattice_0.20-38 colorspace_1.4-1 R6_2.4.1 rlang_0.4.5 dplyr_0.8.5
[13] tools_3.6.3 grid_3.6.3 gtable_0.3.0 xfun_0.12 htmltools_0.4.0 yaml_2.2.1
[19] assertthat_0.2.1 digest_0.6.25 tibble_2.1.3 lifecycle_0.2.0 crayon_1.3.4 Matrix_1.2-18
[25] purrr_0.3.3 ggplot2_3.3.0 rsconnect_0.8.16 glue_1.3.2 evaluate_0.14 rmarkdown_2.1
[31] compiler_3.6.3 pillar_1.4.3 scales_1.1.0 jsonlite_1.6.1 reticulate_1.15-9000 pkgconfig_2.0.3
The python chunk I try running is:
import scipy as sp
import numpy as np
import pandas as pd
df = pd.read_csv("D:/03 PhD Edinburgh related/OneDrive/OneDrive - University of Edinburgh/00 PhD/000 PhD Data/01 Project I Chr Hansen/20200421_analysis_pp16013/20200420_pp16013_analysis.csv")
plt.scatter(df['OD'].values, df['osmolarity.mOSM'].values,
c=df['hydrophobicity'].values,cmap='magma')
plt.xlabel('OD')
plt.ylabel('osmolarity')
plt.title('osmolarity as function of OD and Hydrophobicity')
cbar = plt.colorbar()
cbar.set_label('Hydrophobicity', rotation=270)
plt.show()
I can run the python chunk fine in rStudio and display the graph as expect.
When I try using knitter to make the document it gets to the python chunk and gives the error:
"This application failed to start because it could not find or load
the Qt platform plugin "windows" in "",
reinstalling the application may fix this problem."
This is specifically related to the part using matplotlib. I can create and display the Pandas data frame.
I have tried installing the latest version of reticulate of github.
Thank you for any help in advance.
In my rmarkdown file, it works fine after setting the plugin path of the conda environment being used. You can add the below r code chunk before using matplotlib for python code chunk.
library(reticulate)
py_run_string("import os as os")
py_run_string("os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/Users/[UserID]/Anaconda3/envs/[EnvironmentName]/Library/plugins/platforms'")
I have managed to find the issue in another stack overflow answer this is a duplicate.
For answer please look here.
https://stackoverflow.com/a/50711837/11076186
I basically just save my python plot and then load the saved python plot in r.