Skip to content

Use variable under cursor for r.previewDataframe, r.nrow etc. #137

@andycraig

Description

@andycraig

When there is no selection, it would be good if the following commands operated on the variable the cursor is on:

r.previewDataframe, r.nrow, r.length, r.head, r.thead, r.names

Details

Consider the following file:

library(ggplot2)
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
    geom_point()

When the cursor is on iris in line 2, I think it would make sense for r.previewDataframe etc. to act on iris. But calling r.previewDataframe results in the message 'This does not appear to be a dataframe'. Calling r.nrow results in in following appearing in the console:

> nrow(ggplot(iris, aes(Sepal.Width, Sepal.Length)) +)
Error: unexpected ')' in "nrow(ggplot(iris, aes(Sepal.Width, Sepal.Length)) +)"
> nrow(geom_point())
NULL

The reason is that the above commands use getSelection() to decide what to act on. When there is no selection, getSelection() tries to find the 'minimum runnable block of code', which in the above example is lines 2-3.

@MaTo04 Thank you for adding the r.nrow family of commands! Does this suggestion sound okay to you? I don't want to break a use case I haven't thought of.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions