Closed
Description
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)
Metadata
Metadata
Assignees
Labels
No labels