Python Forum
Rmarkdown opened by python code - errors
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rmarkdown opened by python code - errors
#1
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:

 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.rmd
There is also error window:
[Image: 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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Are there errors in the code for my coin toss systems? Matlibplot is too perfect . Coolkat 0 370 Nov-13-2023, 11:54 AM
Last Post: Coolkat
  When does Python detect Errors? stamp1t 1 439 Oct-21-2023, 05:53 PM
Last Post: deanhystad
  does not save in other path than opened files before icode 3 901 Jun-23-2023, 07:25 PM
Last Post: snippsat
Question How to get html information from a tab of my default browser opened with webbrowser? noahverner1995 2 4,467 Jan-14-2022, 10:02 AM
Last Post: noahverner1995
  My code won't say Player wins or computer wins. No errors. its_a_meLuigi64 2 1,621 Dec-01-2021, 04:43 PM
Last Post: its_a_meLuigi64
  [split] Kera Getting errors when following code example Image classification from scratch hobbyist 3 4,613 Apr-13-2021, 01:26 PM
Last Post: amirian
  Python Request Errors PythonNoob1998 7 3,922 Jan-07-2021, 05:18 PM
Last Post: buran
  2 errors in code numbnumb54 2 2,020 Jul-24-2020, 02:28 PM
Last Post: Marbelous
  Code errors rhyjom 0 1,459 Jun-21-2020, 04:50 PM
Last Post: rhyjom
  Pip Syntax Errors in CMD: Windows 10 and Python 3.8.1 jamesphopper 2 4,443 Feb-08-2020, 07:21 PM
Last Post: jamesphopper

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020