rstudio / reticulate

R Interface to Python
https://rstudio.github.io/reticulate
Apache License 2.0
1.68k stars 327 forks source link

Please allow blind R users to access the `py_help()` output #378

Open jooyoungseo opened 5 years ago

jooyoungseo commented 5 years ago

Hello,

I am a blind person using a screen reading program when doing R. The current output type of reticulate::py_help() is not accessible for assistive technologies like screen reader software. As an alternative, the HTML output format can be made accessible. Please consider either adding the following function to reticulate package or allowing users to specify help output format as an argument for reticulate::py_help() function.

# The function below is retrieved from https://www.r-bloggers.com/digging-into-mbox-details-a-tale-of-tm-reticulate/

py_doc <- function(x) {
  require("htmltools")
  require("reticulate")
  pydoc <- reticulate::import("pydoc")
  htmltools::html_print(
    htmltools::HTML(
      pydoc$render_doc(x, renderer=pydoc$HTMLDoc())
    )
  )
}

Created on 2018-11-08 by the reprex package (v0.2.1.9000)

Session info ``` r devtools::session_info() #> - Session info ---------------------------------------------------------- #> setting value #> version R version 3.5.1 (2018-07-02) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz America/New_York #> date 2018-11-08 #> #> - Packages -------------------------------------------------------------- #> package * version date lib #> assertthat 0.2.0 2017-04-11 [1] #> backports 1.1.2 2017-12-13 [1] #> base64enc 0.1-3 2015-07-28 [1] #> callr 3.0.0 2018-08-24 [1] #> cli 1.0.1 2018-09-25 [1] #> crayon 1.3.4 2017-09-16 [1] #> desc 1.2.0 2018-05-01 [1] #> devtools 2.0.1.9000 2018-11-08 [1] #> digest 0.6.18 2018-10-10 [1] #> evaluate 0.12 2018-10-09 [1] #> fs 1.2.6 2018-08-23 [1] #> glue 1.3.0 2018-10-31 [1] #> highr 0.7 2018-06-09 [1] #> htmltools 0.3.6 2017-04-28 [1] #> knitr 1.20.21 2018-11-07 [1] #> magrittr 1.5 2014-11-22 [1] #> memoise 1.1.0 2017-04-21 [1] #> pkgbuild 1.0.2 2018-10-16 [1] #> pkgload 1.0.2 2018-10-29 [1] #> prettyunits 1.0.2 2015-07-13 [1] #> processx 3.2.0 2018-08-16 [1] #> ps 1.2.1 2018-11-06 [1] #> R6 2.3.0 2018-10-04 [1] #> Rcpp 1.0.0 2018-11-08 [1] #> remotes 2.0.2 2018-10-30 [1] #> rlang 0.3.0.9000 2018-11-06 [1] #> rmarkdown 1.10.15 2018-11-06 [1] #> rprojroot 1.3-2 2018-01-03 [1] #> sessioninfo 1.1.1 2018-11-05 [1] #> stringi 1.2.4 2018-07-20 [1] #> stringr 1.3.1.9000 2018-09-19 [1] #> testthat 2.0.1 2018-10-13 [1] #> usethis 1.4.0.9000 2018-10-31 [1] #> withr 2.1.2 2018-03-15 [1] #> xfun 0.4 2018-10-23 [1] #> yaml 2.2.0 2018-07-25 [1] #> source #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> Github (r-lib/devtools@9780c9f) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> Github (tidyverse/glue@35c61e9) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> Github (yihui/knitr@7ae1db5) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> Github (RcppCore/Rcpp@47db24c) #> CRAN (R 3.5.1) #> Github (r-lib/rlang@f6a719a) #> Github (rstudio/rmarkdown@9875136) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> Github (hadley/stringr@0b5a4c4) #> CRAN (R 3.5.1) #> Github (r-lib/usethis@44dd72c) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> #> [1] C:/Program Files/R/R-3.5.1/library ```
kevinushey commented 5 years ago

Sorry for the late reply!

I'm not very familiar with how screen reading software works and what might make the help content produces inaccessible in this case. reticulate generates documentation as a text file, and then calls file.show() on that file, e.g. its implementation is:

> py_help
function (object)
{
    help <- py_capture_output(import_builtins()$help(object),
        type = "stdout")
    tmp <- tempfile("py_help", fileext = ".txt")
    writeLines(help, con = tmp)
    file.show(tmp, title = paste("Python Help:", object$`__name__`),
        delete.file = TRUE)
}
<bytecode: 0x7fab358771f8>
<environment: namespace:reticulate>

In other words, we're just generating a text file and calling file.show() on that file to show the text contents, which IIUC uses the active pager for showing the file. Is there a reason why that doesn't work well in your case?

jooyoungseo commented 5 years ago

Hello @kevinushey,

Thank you very much for kindly taking care of this case. I have no idea about the deep low level; however, the pane that file.show() brings up is not readable by a screen reading program. More specifically speaking, the main text area of the prompted pane is not readable while the menu bar (e.g., file, edit, etc.) is accessible. Thus, my workaround to interact with any pane that file.show() function pops up is that I copy the main content of the Window by pressing CTRL+A, followed by CTRL+C, and then paste it into the accessible text editor like Notepad by pressing CTRL+V.

On the other hand, any text prompted in Web browser window as an HTML is fully accessible and readable to a screen reader. If you would like to try any free open source screen reader, you can use "NVDA" for Windows and "VoiceOver" for Mac.

kevinushey commented 5 years ago

I believe that you can set:

options(pager = Sys.which("notepad.exe"))

to ensure that file.show() opens files within notepad.exe, rather than whatever default pager is implemented or used by R. If you want this option to be used in future R sessions, you could set it in your ~/.Rprofile file -- see ?Startup for some more details on what R does there in case you're not familiar.

(As a side note: what front-end are you using to run R? Are you running R in a terminal, or using the RGui frontend, or something else?)

jooyoungseo commented 5 years ago

@kevinushey,

I really appreciate your kind help! It works beautifully and accessibly in Notepad now!!

Here is my answer to your question about running R in Windows. I am using R term as RStudio, which I really really love to use, is not accessible to a screen reading program due to its ACE editor. The ACE editor that RStudio has employed is not readable for screen reader users. R GUI is not accessible, either. I have no choice but to manually code in Notepad and copy and paste the code into the R term. Or, I usually make an R script file and run it through Rscript. Emacs is accessible so I utilize Emacs from time to time as well.

kevinushey commented 5 years ago

That's great!

For reference, the latest version of the Ace editor is available at https://ace.c9.io/build/kitchen-sink.html. My understanding is that there is some work being done on this upstream, but I'm not sure if progress has been made just yet -- hopefully once those changes land in Ace they can be easily harvested for the RStudio IDE.