Skip to content

preview option to see changes #267

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

Closed
yonicd opened this issue Oct 31, 2017 · 1 comment
Closed

preview option to see changes #267

yonicd opened this issue Oct 31, 2017 · 1 comment

Comments

@yonicd
Copy link

yonicd commented Oct 31, 2017

worthwhile for PR?

style_preview <- function(obj){
  
  on.exit({unlink(mydir,recursive = TRUE,force = TRUE)},add = TRUE)
  
  mydir <- file.path(tempdir(),'styler')
  
  dir.create(mydir,showWarnings = FALSE)
  
  if( !file.exists(obj) ){
    cat(obj,file = file.path(mydir,'original.R'),sep='\n')
  }else{
    file.copy(obj,file.path(mydir,'original.R'),overwrite = TRUE)
  }
    
  this_text <- readLines(file.path(mydir,'original.R'))
  
  styled <- styler::style_text(this_text)
  
  cat(styled,file = file.path(mydir,'styled.R'),sep='\n')
  
  diffr::diffr(file.path(mydir,'original.R'),file.path(mydir,'styled.R'))  
  
}

ugly_code <- "a<-function( x){1+1}           "

style_preview(ugly_code)
@lorenzwalthert
Copy link
Collaborator

Thanks for reaching out. I am not sure whether that would add much, though i.e. I think the better way to go about that is to have the files checked into a VCS and then simply use git difftool after styling. Also, we tried to eliminate the dependencies to other packages (e.g #182) so styler can be used as a CI step at some point.

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

No branches or pull requests

2 participants