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

datar not working on RStudio notebooks #67

Closed
rleyvasal opened this issue Oct 6, 2021 · 14 comments
Closed

datar not working on RStudio notebooks #67

rleyvasal opened this issue Oct 6, 2021 · 14 comments
Labels
doc Improvements or additions to documentation needs more info

Comments

@rleyvasal
Copy link
Collaborator

I am trying to run code on RStudio R notebooks with datar but the code does not run. I would like to use R notebooks to highlight parts of the datar code and run separately.

@pwwang what is the issue with running datar on RStudio.

datar_rstudio

@pwwang
Copy link
Owner

pwwang commented Oct 6, 2021

This is because the source code is not available for datar/pipda to detect the piping syntax.
See also the following for solutions:

https://pwwang.github.io/datar/caveats/blind/

@rleyvasal
Copy link
Collaborator Author

Hi @pwwang, I did look at the documentation and did figure it out yet. can you provide an example to do the following in RStudio notebook ?

```{python}
from datar.all import * 
from datar.datasets import mtcars
mtcars >> mutate(carb_2 = f.carb)
```

@pwwang
Copy link
Owner

pwwang commented Oct 13, 2021

Here you go:

```{python}
from pipda import options
from datar.all import *
from datar.datasets import mtcars
options.assume_all_piping = True

mtcars >> mutate(carb_2 = f.carb)
```

@rleyvasal
Copy link
Collaborator Author

It did not work, look at the snapshot below:

Rstudio_datar

@pwwang
Copy link
Owner

pwwang commented Oct 14, 2021

Ah, my bad. options.assume_all_piping = True should go before the datar importing.

The following should work:

```{python}
from pipda import options
options.assume_all_piping = True
from datar.all import * 
from datar.datasets import mtcars

mtcars >> mutate(carb_2 = f.carb)
```

@rleyvasal
Copy link
Collaborator Author

It worked, thanks @pwwang

@pwwang pwwang added the doc Improvements or additions to documentation label Oct 15, 2021
@antonio-yu
Copy link

@rleyvasal @pwwang

If in Rsutio with the latest version , it both works whether options.assume_all_piping = True goes before the datar importing or not.

image

@antonio-yu
Copy link

@pwwang @rleyvasal
In the latest Rstudio (version 2021.09.0 ),it both works whether options.assume_all_piping = True goes before the datar importing or not.

{python}
from datar.all import  * 
from pipda import options,register_verb
from datar.datasets import mtcars
options.assume_all_piping = True 
mtcars >> mutate(carb_2=f.carb)

@pwwang
Copy link
Owner

pwwang commented Oct 18, 2021

@antonio-yu
Good to know. I believe it's more related to R/reticulate version.
Theoretically, it should work no matter options.assume_all_piping = True goes before or after datar importing.

@rleyvasal
Copy link
Collaborator Author

@antonio-yu, I can confirm that in the latest version of Rstudio (version 2021.09.0 ), options.assume_all_piping = True works irrespective of where it is entered - this is not an issue anymore.

@pwwang
Copy link
Owner

pwwang commented Oct 21, 2021

Then I will close this for now. If you have any related questions, feel free to reopen it or open new issues.

@pwwang pwwang closed this as completed Oct 21, 2021
@rleyvasal
Copy link
Collaborator Author

@pwwang, just curious, do you know why the pipes work without pipda configuration in VSCode's Jupyter notebooks? but in RStudio notebooks we have to enter the following:

```{python}
from pipda import options
options.assume_all_piping = True
```

@pwwang
Copy link
Owner

pwwang commented Nov 3, 2021

It's all that matters whether the environment (jupyter, rstudio, etc) exposes the source code at runtime. datar/pipda depends on executing to detect the node to tell whether the verbs are calling regularly (e.g. dim(df)) or by piping (df >> dim()). executing did not work for jupyter before, but later it adopted jupyter environment. I will see what I can do with the Rstudio environment.

@pwwang
Copy link
Owner

pwwang commented Nov 3, 2021

@rleyvasal Just took a look at how Rstudio is running python. It actually executes python code with something like eval() wrapped by reticulate. It does not ship with the source code. So currently we need that assumption to let datar work. But I will keep on an eye on reticulate's evolution, and see if it'll be possible in the future. And maybe submit an issue to the repo at some time point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Improvements or additions to documentation needs more info
Projects
None yet
Development

No branches or pull requests

3 participants