Apr-27-2021, 03:13 PM
I have problem when opening R markdown with my python code (pycharm). I use rpy2.robjects and urllib packages. First one is to write code in R script via python. Second one is to open created output:
![[Image: blad.png]](https://i.ibb.co/r6SJ9jS/blad.png)
Like I mentioned Rmarkdown opens but I have no idea how to get rid of that errors.
This problem only occurs when opening Rmarkdown with Python. There is no errors when I open it by R or directly knit Rmarkdown.
import rpy2.robjects as robjects data = robjects.r('print("rmarksdown")') # data = robjects.r('install.packages("rmarkdown", repos = "https://cran.revolutionanalytics.com")') data = robjects.r('if(!require(rmarkdown)) { install.packages("rmarkdown", repos = "https://cran.revolutionanalytics.com"); require(rmarkdown)}') data = robjects.r('print("instalr")') data = robjects.r('if(!require(installr)) { install.packages("installr", repos = "https://cran.revolutionanalytics.com"); require(installr)}') data = robjects.r('rmarkdown::find_pandoc(dir = "C:/Users/R/Downloads/Projekt/packages/pandoc-2.13")') data = robjects.r('myArgs <- commandArgs(trailingOnly = TRUE)') data = robjects.r('nums = as.numeric(myArgs)') data = robjects.r('cat(max(nums))') data = robjects.r('output <- str("C:/Users/R/Downloads/Projekt/Rv2.html")') r.assign('data_vector', data_vector) data = robjects.r('rmarkdown::render("C:/Users/R/Downloads/Projekt/Rv2.rmd", output, params = data_vector)') data = robjects.r('shell.exec("C:/Users/R/Downloads/Projekt/Rv2.html")') data.head() import urllib page = urllib.urlopen("C:/Users/R/Downloads/Projekt/Rv2.html").read() print (page)When I run the python code everything works fine but I also get errors:
[1] "rmarksdown" R[write to console]: Installing package into 'C:/Users/R/Documents/R/win-library/4.0' (as 'lib' is unspecified) R[write to console]: trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/4.0/rmarkdown_2.7.zip' R[write to console]: Content type 'application/zip' R[write to console]: length 3664380 bytes (3.5 MB) R[write to console]: downloaded 3.5 MB package 'rmarkdown' successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\R\AppData\Local\Temp\RtmpSWNQwr\downloaded_packages From cffi callback <function _consolewrite_ex at 0x0000000004979670>: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\rpy2\rinterface_lib\callbacks.py", line 132, in _consolewrite_ex s = conversion._cchar_to_str_with_maxlen(buf, n, _CCHAR_ENCODING) File "C:\ProgramData\Anaconda3\lib\site-packages\rpy2\rinterface_lib\conversion.py", line 133, in _cchar_to_str_with_maxlen s = ffi.string(c, maxlen).decode(encoding) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 0: invalid start byte [1] "instalr" From cffi callback <function _consolewrite_ex at 0x0000000004979670>: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\rpy2\rinterface_lib\callbacks.py", line 132, in _consolewrite_ex s = conversion._cchar_to_str_with_maxlen(buf, n, _CCHAR_ENCODING) File "C:\ProgramData\Anaconda3\lib\site-packages\rpy2\rinterface_lib\conversion.py", line 133, in _cchar_to_str_with_maxlen s = ffi.string(c, maxlen).decode(encoding) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 0: invalid start byte From cffi callback <function _consolewrite_ex at 0x0000000004979670>: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\rpy2\rinterface_lib\callbacks.py", line 132, in _consolewrite_ex s = conversion._cchar_to_str_with_maxlen(buf, n, _CCHAR_ENCODING) File "C:\ProgramData\Anaconda3\lib\site-packages\rpy2\rinterface_lib\conversion.py", line 133, in _cchar_to_str_with_maxlen s = ffi.string(c, maxlen).decode(encoding) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 0: invalid start byte R[write to console]: Welcome to installr version 0.22.0 More information is available on the installr project website: https://github.com/talgalili/installr/ Contact: <[email protected]> Suggestions and bug-reports can be submitted at: https://github.com/talgalili/installr/issues To suppress this message use: suppressPackageStartupMessages(library(installr)) -Inf chr "C:/Users/R/Downloads/Projekt/Rv2.html" R[write to console]: processing file: Rv2.rmdThere is also error window:
![[Image: blad.png]](https://i.ibb.co/r6SJ9jS/blad.png)
Like I mentioned Rmarkdown opens but I have no idea how to get rid of that errors.
This problem only occurs when opening Rmarkdown with Python. There is no errors when I open it by R or directly knit Rmarkdown.