tidy_dir() first looks for all the R scripts under a directory (using
the pattern "[.][RrSsQq]$"), then uses tidy_source to
tidy these scripts. The original scripts will be overwritten with reformatted
code if reformatting was successful. You may need to back up the original
directory first if you do not fully understand the tricks used by
tidy_source. tidy_file() formats specified R scripts.
tidy_dir(path = ".", recursive = FALSE, ...) tidy_file(file, ...)
| path | the directory |
|---|---|
| recursive | whether to recursively look for R scripts under |
| ... | other arguments to be passed to |
| file | a vector of filenames |
Invisible NULL.
library(formatR) path = tempdir() file.copy(system.file("demo", package = "base"), path, recursive = TRUE)#> [1] TRUEtidy_dir(path, recursive = TRUE)#>#>#>#>#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/base/demo/error.catching.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/base/demo/is.things.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/base/demo/recursion.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/base/demo/scoping.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in parse(text = lines, keep.source = TRUE) : #> <text>:9:9: unexpected numeric constant #> 8: junk <- scan(file="",list(0,0),nmax=999*2) #> 9: 1.144 0.832 #> ^#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:9:45: unexpected SPECIAL #> 8: invisible(".BeGiN_TiDy_IdEnTiFiEr_HaHaHa.HaHaHa_EnD_TiDy_IdEnTiFiEr") #> 9: if ( doExtras <- cluster ::: doExtras ( ) ) %InLiNe_IdEnTiFiEr% #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/graphics/demo/graphics.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/graphics/demo/Hershey.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/graphics/demo/image.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/graphics/demo/Japanese.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/graphics/demo/persp.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/graphics/demo/plotmath.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grDevices/demo/colors.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:48:16: unexpected SPECIAL #> 47: } #> 48: if ( ! fixup ) %InLiNe_IdEnTiFiEr% #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/displaylist.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/frame.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/grid.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/grobs.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/interactive.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/locndimn.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/moveline.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/nonfinite.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/plotexample.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:83:1: unexpected symbol #> 82: invisible(".BeGiN_TiDy_IdEnTiFiEr_HaHaHa# NOTE that the axis on the boxplot represents actual (y - x) values BUT to make.HaHaHa_EnD_TiDy_IdEnTiFiEr") #> 83: invisible #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/saveload.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/sharing.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/grid/doc/viewports.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/lattice/demo/intervals.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/lattice/demo/labels.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:123:1: unexpected symbol #> 122: invisible(".BeGiN_TiDy_IdEnTiFiEr_HaHaHa## par.settings = list(clip = list(strip = 'on')),.HaHaHa_EnD_TiDy_IdEnTiFiEr") #> 123: strip #> ^#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:5:10: unexpected '(' #> 4: horizontal = TRUE , #> 5: invisible( #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch01.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch02.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch03.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch04.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch05.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch06.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch07.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch08.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch09.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch10.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch11.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch12.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch13.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch14.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/MASS/scripts/ch15.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in parse(text = lines, keep.source = TRUE) : #> <text>:156:4: unexpected numeric constant #> 155: Y <- scan() #> 156: 12 14 #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/Matrix/data/CAex.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:10:44: unexpected SPECIAL #> 9: `slot<-` <- methods :: `slot<-` #> 10: for ( n in c ( "Dim" , "i" , "p" , "x" ) ) %InLiNe_IdEnTiFiEr% #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/Matrix/data/USCounties.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/Matrix/doc/Comparisons.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/Matrix/doc/Design-issues.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/Matrix/doc/Intro2Matrix.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/Matrix/doc/Introduction.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/Matrix/doc/sparseModels.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:10:50: unexpected SPECIAL #> 9: invisible(".BeGiN_TiDy_IdEnTiFiEr_HaHaHa.HaHaHa_EnD_TiDy_IdEnTiFiEr") #> 10: if ( ! exists ( "paste0" , .BaseNamespaceEnv ) ) %InLiNe_IdEnTiFiEr% #> ^#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:52:1: unexpected '!' #> 51: invisible(".BeGiN_TiDy_IdEnTiFiEr_HaHaHa## allow for 'completion' of (NULL, <names>) dimnames of symmetricMatrix:.HaHaHa_EnD_TiDy_IdEnTiFiEr") #> 52: ! #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/Matrix/test-tools.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/nlme/mlbook/ch04.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/nlme/mlbook/ch05.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:48:19: unexpected SPECIAL #> 47: intervals ( fm1Stool ) #> 48: plot ( fm1Stool , %InLiNe_IdEnTiFiEr% #> ^#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:38:43: unexpected SPECIAL #> 37: machineLRTsim <- simulate.lme ( fm1Machine , m2 = fm2Machine , nsim = 1000 ) #> 38: plot ( machineLRTsim , df = c ( 0 , 1 ) , %InLiNe_IdEnTiFiEr% #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/nlme/scripts/ch03.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/nlme/scripts/ch04.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/nlme/scripts/ch05.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:86:14: unexpected SPECIAL #> 85: options ( contrasts = c ( "contr.treatment" , "contr.poly" ) ) #> 86: if ( FALSE ) %InLiNe_IdEnTiFiEr% #> ^#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:259:1: unexpected symbol #> 258: invisible(".BeGiN_TiDy_IdEnTiFiEr_HaHaHa# start = c(fixef(fm5Ovar.lme), 1)).HaHaHa_EnD_TiDy_IdEnTiFiEr") #> 259: start #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/nlme/scripts/runme.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/parallel/doc/parallel.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/rpart/doc/longintro.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/rpart/doc/usercode.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/stats/demo/glm.vr.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/stats/demo/lm.glm.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:108:31: unexpected SPECIAL #> 107: with ( nlfgh , #> 108: stopifnot ( minimum < 1e-15 , %InLiNe_IdEnTiFiEr% #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/stats/demo/smooth.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/adjcurve.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/approximate.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/compete.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/concordance.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/population.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/splines.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/survival.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/tiedtimes.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Error in base::parse(text = code, keep.source = FALSE) : #> <text>:219:26: unexpected SPECIAL #> 218: time = rep ( c ( 90 , 180 , 365 ) , 2 ) , #> 219: status = rep ( 0 , 6 ) , %InLiNe_IdEnTiFiEr% #> ^#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/survival/doc/validate.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/tcltk/demo/tkcanvas.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/tcltk/demo/tkdensity.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/tcltk/demo/tkfaq.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/tcltk/demo/tkttest.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/tcltk/exec/Tk-frontend.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection#>#> Warning: cannot open file '/tmp/RtmpAz8giZ/renv-system-library/utils/doc/Sweave.R': Permission denied#> Error in file(file, ifelse(append, "a", "w")) : #> cannot open the connection