MilesMcBain / packup

Collect, stow, and alphabetise library() calls in your R files.
Other
59 stars 4 forks source link

move the entire line, possibly including comments #3

Closed jonocarroll closed 7 years ago

jonocarroll commented 7 years ago

I gave this package a go (love it) and noticed it went wonky when I had a comment after my library call, which got orphaned. This PR allows the entire line to be collected and moved, so

# do the things
x <- y + z
library(package)
x <- r + s

# more code
library(anotherPkg) # used for cool things
l <- m + n

ends up as

library(anotherPkg) # used for cool things
library(package)
# do the things
x <- y + z

x <- r + s

# more code

l <- m + n
jonocarroll commented 7 years ago

Just some further thoughts though;

MilesMcBain commented 7 years ago

Thanks Jono. Handling comments is a useful addition!

Unfortunately I don't think the addin can delete the line. This is a limitation of rstudioapi which I have opened an issue on.

Reordering is tricky. I think it's very hard to please everyone. I thought that at least if it's alphabetical it's easy to then juggle the order to avoid masking issues. But I get your point that if you had already got an order that worked this could be annoying.

MilesMcBain commented 7 years ago

Now moves entire lines. :) Fix for leftover empty lines hanging out on deletelines branch until the related RStudio fix has been in stable for a little while.