@@ -46,7 +46,7 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
4646 checkpointLocation = " ~/" ,
4747 verbose = TRUE ,
4848 use.knitr = system.file(package = " knitr" ) != " " ) {
49-
49+
5050 if (! missing(" R.version" ) && ! is.null(R.version )){
5151 if (! correctR(as.character(R.version ))){
5252 message <- sprintf(" Specified R.version %s does not match current R (%s)" ,
@@ -57,41 +57,39 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
5757 stop(message )
5858 }
5959 }
60-
60+
6161 checkpointLocation = authorizeFileSystemUse(checkpointLocation )
62-
62+
6363 fixRstudioBug()
64-
64+
6565 if (! createFolders(snapshotDate = snapshotDate , checkpointLocation = checkpointLocation ))
6666 stop(" Unable to create checkpoint folders at checkpointLocation = \" " , checkpointLocation , " \" " )
67-
68-
67+
68+
6969 snapshoturl <- getSnapshotUrl(snapshotDate = snapshotDate )
70-
71-
70+
71+
7272 compiler.path <- system.file(package = " compiler" , lib.loc = .Library [1 ])
73- # set repos
74- setMranMirror(snapshotUrl = snapshoturl )
75-
73+
7674 libPath <- checkpointPath(snapshotDate , type = " lib" , checkpointLocation = checkpointLocation )
7775 installMissingBasePackages(checkpointLocation = checkpointLocation )
78-
76+
7977 # Set lib path
8078 setLibPaths(checkpointLocation = checkpointLocation , libPath = libPath )
81-
79+
8280 # Scan for packages used
8381 exclude.packages = c(" checkpoint" , # this very package
8482 c(" base" , " compiler" , " datasets" , " graphics" , " grDevices" , " grid" ,
8583 " methods" , " parallel" , " splines" , " stats" , " stats4" , " tcltk" ,
8684 " tools" , " utils" )) # all base priority packages, not on CRAN or MRAN
8785 packages.installed <- unname(installed.packages()[, " Package" ])
88-
86+
8987 if (isTRUE(scanForPackages )){
9088 mssg(verbose , " Scanning for packages used in this project" )
9189 pkgs <- projectScanPackages(project , use.knitr = use.knitr )
9290 packages.detected <- pkgs [[" pkgs" ]]
9391 mssg(verbose , " - Discovered " , length(packages.detected ), " packages" )
94-
92+
9593 if (length(pkgs [[" error" ]]) > 0 ){
9694 files.not.parsed <- pkgs [[" error" ]]
9795 mssg(verbose , " Unable to parse " , length(pkgs [[" error" ]]), " files:" )
@@ -103,18 +101,20 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
103101 packages.detected <- character (0 )
104102 files.not.parsed <- character (0 )
105103 }
106-
107-
104+
105+
108106 packages.to.install <- setdiff(packages.detected , c(packages.installed , exclude.packages ))
109-
107+
110108 # detach checkpointed pkgs already loaded
111-
109+
112110 packages.in.search <- findInSearchPath(packages.to.install )
113111 detachFromSearchPath(packages.in.search )
114-
112+
115113 # check if packages are available in snapshot
116-
114+
117115 if (length(packages.to.install ) > 0 ) {
116+ # set repos
117+ setMranMirror(snapshotUrl = snapshoturl )
118118 not.available <- ! packages.to.install %in% available.packages()[, " Package" ]
119119 if (sum(not.available > 0 )){
120120 mssg(verbose , " Packages not available in repository and won't be installed:" )
@@ -124,9 +124,9 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
124124 } else {
125125 not.available <- character (0 )
126126 }
127-
127+
128128 # install missing packages
129-
129+
130130 if (length(packages.to.install ) > 0 ) {
131131 mssg(verbose , " Installing packages used in this project " )
132132 for (pkg in packages.to.install ){
@@ -144,15 +144,15 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
144144 } else {
145145 if (isTRUE(scanForPackages )) mssg(verbose , " No packages found to install" )
146146 }
147-
147+
148148 # Reload detached packages
149149 if (length(packages.in.search > 0 )){
150150 lapply(packages.in.search , library , character.only = TRUE , quietly = TRUE )
151151 }
152-
152+
153153 mssg(verbose , " checkpoint process complete" )
154154 mssg(verbose , " ---" )
155-
155+
156156 z <- list (
157157 files_not_scanned = files.not.parsed ,
158158 pkgs_found = packages.detected ,
@@ -161,30 +161,40 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
161161 )
162162 invisible (z )}
163163
164+
165+ # ------------------------------------------------------------------------
166+
167+
164168setMranMirror <- function (snapshotDate , snapshotUrl = checkpoint ::: getSnapShotUrl(snapshotDate )){
165169 options(repos = snapshotUrl )}
166170
167171setLibPaths <- function (checkpointLocation , libPath ){
168- assign(" .lib.loc" , c(libPath , checkpointBasePkgs(checkpointLocation )), envir = environment(.libPaths ))}
172+ assign(" .lib.loc" , c(libPath , checkpointBasePkgs(checkpointLocation )), envir = environment(.libPaths ))}
169173
170174mranUrl <- function ()" http://mran.revolutionanalytics.com/snapshot/"
171175
172176getSnapshotUrl <- function (snapshotDate , url = mranUrl()){
173177 mran.root = url(url )
178+ snapshot.url = paste(gsub(" /$" , " " , url ), snapshotDate , sep = " /" )
174179 on.exit(close(mran.root ))
175180 tryCatch(
176181 suppressWarnings(readLines(mran.root )),
177182 error =
178183 function (e ) {
179- stop(sprintf(" Unable to reach MRAN: %s" , e $ message ))})
180- snapshot.url = paste(gsub(" /$" , " " , url ), snapshotDate , sep = " /" )
184+ warning(sprintf(" Unable to reach MRAN: %s" , e $ message ))
185+ return (snapshot.url )
186+ }
187+ )
181188 con = url(snapshot.url )
182189 on.exit(close(con ), add = TRUE )
183190 tryCatch(
184191 suppressWarnings(readLines(con )),
185192 error =
186193 function (e ) {
187- stop(" Unable to find snapshot on MRAN" )})
194+ warning(" Unable to find snapshot on MRAN" )
195+ return (snapshot.url )
196+ }
197+ )
188198 snapshot.url }
189199
190200
0 commit comments