-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_groundhog.r
609 lines (416 loc) · 20.9 KB
/
test_groundhog.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
######################################################################################
#INTRODUCTION
# Groundhog testing is not automatized because an R session needs to be restarted
# after each test, and the output carefully (humanly) evaluated. Also
# the testing requires conflicts with local libraries and the installation of
# 100s of packages; so testing is done 'by hand', using the scripts below
#
######################################################################################
#OUTLINE
#Set 0 - Various forms of calling packages to be loaded
#Set 1 - Enumerated conflicts '
#Set 2 - Previous Bugs
#Set 3 - Install many packages
#Set 4 - Remote packages
#Set 5 - others
#Set 6 - Restore Library
#Version being tested (only locally available)
#install.packages('https://groundhogr.com/groundhog_3.1.0.9001.tar.gz',repos=NULL)
install.packages('C:/Dropbox (Penn)/groundhogR/groundhog_3.1.2.9001.tar.gz',repos=NULL)
library('groundhog')
set.groundhog.folder('c:/temp/103')
test.day <- groundhog:::get.r.majmin.release()+45 #release of this R version +K days
#Set 0 - various forms of calling packages to be loaded
#Missing/wrong arguments
#Missing pkg
groundhog.library(date=test.day)
#Missing date
groundhog.library('rio')
#Date is a vector
groundhog.library('rio',c('2023-01-01','2023-02-01'))
#wrong format for date
groundhog.library(2,2)
#Nonexistent pkg on cran
groundhog.library('tio',test.day)
#inexistent pkg on github
groundhog.library('github::crsh/powerful_999',test.day)
#Remote with multiple
pkgs<-c('pwr','crsh/papaja')
groundhog.library(pkgs,test.day)
#Remote with multiple
pkgs<-c('pwr','metafor')
groundhog.library(pkgs,test.day , force.source.main = TRUE)
groundhog.library(pkgs,test.day , force.install.main = TRUE)
#These should work
#Single package, with and without quotes
library('groundhog')
groundhog.library('pwr',test.day) #quotes
groundhog.library(pwr,test.day) #no quotes
#Object containing a single package
pkg1='pwr'
groundhog.library(pkg1,test.day)
#Vector containing many packages
pkg=c('pwr','metafor')
groundhog.library(pkg,test.day) #single package, no quotes, show warning to use ""
#Direct call to many packages
groundhog.library(c('pwr','metafor'),test.day)
#Sandwiching library and combine already attached with successfully atched
library('groundhog')
groundhog.library("
library('pwr')
library(metafor)
library(Hmisc)
library(jsonlite)",
test.day)
#Outdate R
library('groundhog')
groundhog.library('haven','2022-04-01')
#######################################
#Set 1 - Enumerated conflicts '
# 2.1) A *requested.pkg* was previously loaded with groundhog but different version or repository
#Groundhog CRAN date 1 & CRAN date 2
library('groundhog')
groundhog.library('pwr',test.day)
groundhog.library('pwr',test.day-1400,tolerate.R.version = groundhog:::get.rversion())
#Groundhog CRAN date 1 & GIT 2
library('groundhog')
groundhog.library('pwr',test.day)
groundhog.library('heliosdrm/pwr',test.day)
#Groundhog GIT date 1 & GIT 2
library('groundhog')
groundhog.library('heliosdrm/pwr',test.day)
groundhog.library('heliosdrm/pwr',test.day+1)
# 2.2) A *dependency* was loaded for a different repos or date
#Groundhog CRAN date 1 & CRAN date 2
#1 Single conflicting pkg, show it
library('groundhog')
groundhog.library('zip',test.day-800,tolerate.R.version = groundhog:::get.rversion())
groundhog.library('rio',test.day)
groundhog.library('rio',test.day,ignore.deps = 'zip') #this does not download the new zip, uses the old one instead
#2 More than 5 conflicting pkg, mention them only, not listed
library('groundhog')
groundhog.library('haven',test.day-10,tolerate.R.version = groundhog:::get.rversion())
groundhog.library('rio',test.day+150)
.view.conflicts
# 2.3) TEST BY HAND IN BAT FILE WITH NON-INTERACTIVE SESSION
#*Any* conflict on a non-interactive session (because we cannot request after installation they restart in a forceful way)
#Run this from R script non-interactively
library('groundhog')
test.day <- groundhog:::get.r.majmin.release()+105 #release of this R version + 45 days
groundhog.library('haven',test.day-20,tolerate.R.version = groundhog:::get.rversion())
groundhog.library('rio',test.day+80)
#3 AFTER (so a conflict with a non-groundhog loaded pkg)
library('groundhog')
groundhog.library('pwr',test.day-1200,tolerate.R.version = groundhog:::get.rversion())
#restart session
library('groundhog')
library('pwr') #loading the older version
groundhog.library('pwr',test.day)
#Date is too recent for CRAN
library('groundhog')
groundhog.library('pwr',Sys.Date()-1)
#Date is too recent for github (will not show it if package is already installed)
#temporarily change groundhog folder so warning is shown
d0=get.groundhog.folder()
temp_path<-paste0(d0,'/test1')
set.groundhog.folder(temp_path)
#>> restart session
library(groundhog)
groundhog.library('heliosdrm/pwr',Sys.Date()-50) #this is shown once, and then a cookie will not show it for 30 minutes
#return to baseline\
library(groundhog)
set.groundhog.folder(d0)
########################################################################
#Set 2 - Previous Bugs
test.day <- groundhog:::get.r.majmin.release()+45 #release of this R version + 45 days
#1) Loading but not attaching dependencies (verify one can run lmer() without lme4::)
library('groundhog')
pkgs=c("robustlmm","R2ucare")
groundhog.library(pkgs,test.day)
lmer(NA) #should read error in formula rather than cannot find function
#2) Folder with space names
library('groundhog')
current.folder<-get.groundhog.folder()
set.groundhog.folder(paste0(current.folder,'/temp groundhog folder'))
groundhog.library('jsonlite',test.day)
#Reset the default folder
set.groundhog.folder(current.folder)
#3) Source a script which uses groundhog with a vector of packages, used to stop executing
source("http://groundhogr.com/source_file_for_test_groundhog.r")
#4) tolerate
#DONE above for other tasks
#5) Source
library('groundhog')
groundhog.library('jsonlite',test.day,force.install=TRUE,force.source = TRUE)
#6) Main source and main install.
library('groundhog')
groundhog.library('metafor',test.day,force.install.main=TRUE , force.source.main= TRUE)
groundhog.library('rio',test.day, force.install.main=TRUE , force.source.main= FALSE)
#7) Include suggests
library('groundhog')
pks='rio'
groundhog.library(pks, test.day ,include.suggests = TRUE)
#8) Update cran to
groundhog:::load.cran.toc(TRUE)
#8 #DO THIS BY HAND:::delete R_groundhog ('main folder') verifying what happens if consent is given denied
#Save folder being used for that will be deleted next
gf=get.groundhog.folder()
#Should prompt
library('groundhog')
groundhog.library('pwr',test.day)
#Then run a .bat file ('not interactive.bat') that executes R code doing library('groundhog') and trying to run groundhog.library().
#It should prompt running set.groundhog.folder()
#use files 'not_interactive.bat', modifying the location of the R script and R binary used to execute it"
set.groundhog.folder('c:/temp/105')
#9 ) Base packages
groundhog.library('stats',test.day) #already attached always
groundhog.library('parallel',test.day) #gets attached, same version always
groundhog.library('mgcv',test.day) #gets installed to local (recommended pkg come included but can be updated)
########################################################################
#Set 3 - Install many packages
#Function
# TESTING GROUNDHOG
#
#This script enables testing {groundhog} under various scenarios
#
#Because groundhog installs packages, and because the goal is 0 dependencies for groundhog
#these tests are not implemented using {testthat} nor are they run automatically
#This script is meant merely for sharing how groundhog is tested by the maintainer of the package
#i.e., for transparency of quality control. It is also useful for people who want to contribute to
#the package
#############################################################################################
#Function that Tests sets of packages loaded/installed from groundhog
test.groundhog <- function(set.of.packages=c(1:100),seed=111,groundhog.day=NULL,day.offset=0, force.source=FALSE)
{
#Arguments
#set.of.packages: the number indicates their ranking of 'most downloaded' in a relatively recent day
# of CRAN logs (recent respect to groundhog.day
# a negative number implies installing a random subset of available packages
#seed: packages are installed in random order, for a random date,
# seed gives reproducibility of possibel issues
#groundhog.day as in groundhog.library()
#start.with in case an issue is found which is idyosincratic for a pakcage, testing can start from
# the next package in the list with this argument
#set the seed
set.seed(seed)
#If groundhoglibrary does not exist, create it
if (!file.exists(get.groundhog.folder())) dir.create(get.groundhog.folder(),showWarnings = FALSE)
#0 Which version of R is being used?
r.majmin=groundhog:::get.r.majmin() #Which R version is being used
#1. Date: Random number of days after release of majmin of R
if (is.null(groundhog.day)) groundhog.day=groundhog:::get.r.majmin.release()+sample(size=1,1:150)+day.offset
#2 Load most downloaded packages if a positive number is entered
if (sum(set.of.packages)>0)
{
#2.2 most.downloaded.path
file_name <- paste0("rank_" , r.majmin , ".csv")
local.path <- paste0(get.groundhog.folder(), "/" , file_name)
most.downloaded.path <- paste0("http://groundhogr.com/data/",file_name)
#2.3 if not available locally, download from http://groundhogr.com
if (!file.exists(local.path)) download.file(most.downloaded.path, local.path)
#2.4 read locally
packages <- read.csv(local.path)
#2.5 Sort
packages <- packages[order(-packages$downloads),]
#2.5.1 never install gmailr, it creates error because it replaces the base function message() (!!!!)
packages <- packages[packages$pkg!='gmailr',]
#2.6 Keep those selected
packages <- packages[set.of.packages,]$pkg
#2.7 Shuffle the order
packages <- sample(packages)
}
#3 Get available packages otherwise
if (sum(set.of.packages)<0)
{
packages <- data.frame(available.packages())$Package #all available packages
packages <- sample(packages, size= -set.of.packages) #in random order, choose the negative number entered
#for example, select 50 at rnadom if number entered in -50
}
#4 Loop installing
j <- 1
#4.1 Base and recommended packages
ip <- data.frame(installed.packages(),stringsAsFactors = FALSE,row.names = NULL)
base <- subset(ip, Priority=="base")$Package
recommended <- subset(ip, Priority=="recommended")$Package
for (pkgk in packages)
{
#Counter
cat(
"\n--------- ",j," out of ",length(packages),"-- package:",pkgk," using R-",r.majmin," on ",
as.character(as.Date(groundhog.day,"yyyy-m-d")),"\n"
)
#Execute groundhog.library()
exec_line=paste0("groundhog.library('", pkgk, "'," , "'", groundhog.day , "',force.source=",force.source,")") #line to execute
eval(parse(text=exec_line))
#Verify every package in snowball is availablerunning
snowball.k=groundhog:::get.snowball(pkgk,groundhog.day)
ip = data.frame(installed.packages(),row.names = NULL,stringsAsFactors = FALSE)
ip.pkg_vrs = paste0(ip$Package , "_" , ip$Version)
#ignore deps
ignore.deps <- groundhog:::ignore.deps_default()
if (!all(snowball.k$pkg_vrs %in% ip.pkg_vrs | snowball.k$pkg %in% ignore.deps)) {
message("----------groundhog tester says: INSTALLATION ERROR---------------")
message("active packages:\n")
cat(sort(active$pkg_vrs))
message("\n\nsnowball:\n")
cat(sort(snowball.k$pkg_vrs))
return(list(pkg=pkgk, active=sort(active$pkg_vrs),snowball=snowball.k$pkg_vrs))
break
} else {
message("Groundhog tester says:\nSUCCESS\nAll pkg_vrs in snowball are available for j=",j," (",pkgk,")")
message("############################")
} #End of check for installation/loading success
j<-j+1
}#End of install loop
} #end of function
# Installation can be tested with most downloaded packages as of the release of R's version matching that being used
# or based on available packages when testing.
library('groundhog')
test.groundhog(1:10)
#Switch to copying
groundhog:::save.cookie('copy_instead_of_renaming')
groundhog:::cookie.exists("copy_instead_of_renaming")
#Same pkgs again with an ofset of time and the copy method
test.groundhog(1:10,day.offset=140)
help(try.renaming.method.again)
library('groundhog')
#back to top 10, should not install anything
test.groundhog(1:10)
try.renaming.method.again()
test.groundhog(120:129)
test.groundhog(560:569)
########################################################################
#Set 4 - Remote packages
#4.1 - Run in 4.0.3
#---------------------------------------------------
#Test conflicts when a remote depends on a remote
# Key is whether the second package, a dependency of the 1st, is loaded without an error
library('groundhog')
groundhog.library('crsh/papaja',test.day+10)
groundhog.library('tidymodels/broom',test.day)
# Same, but now with non matching dates
library('groundhog')
groundhog.library('crsh/papaja','2016-10-01')
groundhog.library('tidymodels/broom','2016-10-02') #SHOULD NOT WORK
# Load remote, then try to load CRAN version
library('groundhog')
groundhog.library('crsh/papaja','2016-10-01') #remote broom dependency
groundhog.library('broom','2016-10-01')
#Should say script needs to be revised
#remote dependency already loaded
library('groundhog')
groundhog.library('tidymodels/broom','2020-04-01')
groundhog.library('crsh/papaja','2020-04-01')
#Should work
# remote dependency already loaded, but wrong date
library('groundhog')
test.day <- groundhog:::get.r.majmin.release()+105 #release of this R version + 45 days
#---------------------------------------------------------------------------------
#4.2 - Test some popular github packages
test.day <- groundhog:::get.r.majmin.release()+45 #release of this R version +K days
library('groundhog')
groundhog.library( "yihui/knitr",test.day)
groundhog.library( "crsh/papaja",test.day)
groundhog.library( "weirichs/eatModel",test.day) #this would not load in groundhog v2.2.1 but loads with v3.0.0
#it also used to have the wrong pkg name eatTools, and won't install with the wrong name
groundhog.library( "mlr-org/mlr",test.day)
groundhog.library( "joey711/phyloseq",test.day) #fails, no bioconductor
groundhog.library( "kassambara/survminer",test.day)
#Test now with copying
groundhog:::save.cookie('copy_instead_of_renaming')
groundhog:::cookie.exists("copy_instead_of_renaming")
groundhog.library( "yihui/knitr",test.day + 90)
groundhog.library( "crsh/papaja",test.day+100)
groundhog.library( "mlr-org/mlr",test.day)
groundhog.library( "kassambara/survminer",test.day)
########################################################################
#Set 5 - Others
#5.1 Conflict in source install
library('groundhog')
groundhog.library('metafor','2022-05-01')
library(metafor)
library('groundhog')
groundhog.library('metafor','2023-03-01',force.install.main=TRUE,force.source.main=TRUE)
#5.2 Set dropbox path
library('groundhog')
gd=get.groundhog.folder()
set.groundhog.folder('c:/dropbox/temp/1001')
groundhog.library('jsonlite','2023-03-01')
set.groundhog.folder(gd)
########################################################################
#Set 6 - Restore Library
#6.1 Undo all changes in tests above (strong tes)
library('groundhog')
restore.library()
#--------------------------------------------------
#function that get dataframe with installed packages, and pkg_vrs included
get.ip.local <-function(){
path <- .libPaths()[1]
ip <- data.frame(utils::installed.packages(path), row.names = NULL, stringsAsFactors = FALSE)
if (nrow(ip)>0) ip$pkg_vrs <- paste0(ip$Package,"_",ip$Version)
if (nrow(ip)==0) ip$pkg_vrs <- character()
ip <- ip[,c(names(ip) %in% c("LibPath", "Package","Version","pkg_vrs"))]
if (nrow(ip)>0) {
description.path <- paste0(ip$LibPath, "/" , ip$Package , "/DESCRIPTION")
ip$md5 <- tools::md5sum(description.path)
}
if (nrow(ip)==0) ip$md5 <- character()
return(ip)
}
groundhog::set.groundhog.folder('c:/temp/100')
#6.2 Testing three packages with multiple date changes
#1 Take an inventory of packages
library('groundhog')
ip0=get.ip.local()
#1 Do first change, which should create a restore point before it
#restart
library('groundhog')
groundhog.library(c('metafor'),'2022-05-15')
ip1=get.ip.local()
#5 Do another change
#restart session
library('groundhog')
groundhog.library(c('metafor'),'2023-01-15')
ip2=get.ip.local()
#6 another
#restart session
library('groundhog')
groundhog.library(c('rio'),'2023-01-15')
ip3=get.ip.local()
#6 Use copy method
#restart session
library('groundhog')
groundhog:::save.cookie('copy_instead_of_renaming')
groundhog:::cookie.exists("copy_instead_of_renaming")
groundhog.library('jsonlite','2022-05-15')
ip4=get.ip.local()
#7 Add another package copying
library('groundhog')
groundhog.library(c('jsonlite','rio'),'2023-01-15')
ip5=get.ip.local()
#8 Install without groundhog
install.packages('this.path')
ip6=get.ip.local()
#9 One more as renaming
library('groundhog')
try.renaming.method.again()
groundhog.library('metafor','2023-03-15')
ip7=get.ip.local()
#8 Restore
restore.library()
ip8=get.ip.local()
sum(!ip0$pkg_vrs %in% ip1$pkg_vrs)
sum(!ip0$pkg_vrs %in% ip2$pkg_vrs)
sum(!ip0$pkg_vrs %in% ip3$pkg_vrs)
sum(!ip0$pkg_vrs %in% ip4$pkg_vrs)
sum(!ip0$pkg_vrs %in% ip5$pkg_vrs)
sum(!ip0$pkg_vrs %in% ip6$pkg_vrs)
sum(!ip0$pkg_vrs %in% ip8$pkg_vrs)
########################################################################
#Set 7 - Install from source
library(groundhog)
test.day <- groundhog:::get.r.majmin.release()+45 #release of this R version +K days
set.groundhog.folder('c:/temp/1010')
groundhog.library('metafor',test.day,force.source=TRUE)
df=data.frame(x=1,z=3)
gView(df)