Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing "run chunk" through monkey patching #676

Closed
ElianHugh opened this issue Jun 20, 2021 · 1 comment
Closed

Enhancing "run chunk" through monkey patching #676

ElianHugh opened this issue Jun 20, 2021 · 1 comment

Comments

@ElianHugh
Copy link
Collaborator

I was looking at a few issues related to rmarkdown, particularly running chunks (e.g. #560). Rstudio seems to run a background process for querying repl state (among other things), but with the difficulties of #440 that doesn't seem like its on the table for vscode-R.

Piggybacking off the work on the rstudioapi, I figured one option would be to monkey patch functions such as reticulate::repl_python, in order to set state before and after their call. Super duper rough example:

.vsc.repl_python <- reticulate::repl_python
.vsc.patched_repl_python <- function() {
    .vsc.repl_status <<- "python"
    .vsc.repl_python()
    .vsc.repl_status <<- "r"
}
assignInNamespace(x = "repl_python", value = .vsc.patched_repl_python, ns = "reticulate")

This could then be picked up in the globalenv.json file, and then queried in the runChunks method. This wouldn't have to be limited to reticulate, and could be used for other packages with REPL functions, such as JuliaCall::console.

I guess some questions would be:

  1. Do we want to support running other language chunks?
    Vscode has many extensions for python, which would provide a far better coding experience than using a reticulate call. However, this does restrict the usefulness of .rmd files somewhat.

  2. Is monkey patching a viable/healthy solution to the issue?
    We don't want to impact on development process, so any monkey patching that occurs would have to be fairly lightweight. There's also the issue of people being unaware that monkey patching took place, and then being confused when they examine the method.

@ElianHugh
Copy link
Collaborator Author

An example of keeping track of the current repl through monkey patching:

3G7QLk67T4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant