forked from biometry/bipartite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbipartite_testfile.R
executable file
·533 lines (422 loc) · 23.4 KB
/
bipartite_testfile.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
# This now is the command line version; in particular the R CMD CHECK is better here than in the devtools version (which throws an error related to roxygen)
# workflow:
## At the bottom of the testfile is the workflow on the old computer, where the compression did not work and thus several detours had to be taken.
Sys.setenv("R_CHECK_RD_VALIDATE_RD2HTML"=FALSE) # to switch off html-syntax check in R CMD check
## DOES NOT WORK! (I used "_" before and after the option, as indicate in the NEWS-section.)
#Sys.getenv()
R CMD build bipartite --compact-vignettes=gs+qpdf
R CMD check bipartite_2.19.tar.gz --as-cran
# upload to https://win-builder.r-project.org/upload.aspx and check on R-devel!
R CMD install bipartite_2.19.tar.gz
## bipartite test file ##
## CHECK R-CONSOLE FOR RED TEXT INDICATING ERRORS!! ##
## run this file after every change in bipartite before submitting it to CRAN!!
library(bipartite)
library(testthat) # if we want to formally test expressions and functions!
#source("/Users/Carsten/Data/aktuell/Networks/bipartite/bipartite/R/computeModules.R")
#source("/Users/Carsten/Data/aktuell/Networks/bipartite/bipartite/R/restrictednull.R")
# lazy load data does not require data to be loaded via "data(.)"!
# as.one.mode
image(as.one.mode(Safariland))
visweb(as.one.mode(Safariland, project="lower", fill=NA), NA.col="green") #NA.col should have no effect and cause no problem!
# check fill=NA and visweb's NA.col:
visweb(as.one.mode(vazquenc, fill=NA), NA.col="green")
# array2linkmx
array2linkmx(webs2array(Safariland, vazquenc))
# betalinkr
#--case1: testdata of frame2webs (a case with low overlap and no shared links) --
testdata <- data.frame(higher = c("bee1","bee1","bee1","bee2","bee1","bee3"),
lower = c("plant1","plant2","plant1","plant2","plant3","plant4"),
webID = c("meadow","meadow","meadow","meadow","bog","bog"), freq=c(5,1,1,1,3,7))
testarray <- frame2webs(testdata, type.out="array")
betalinkr(testarray, distofempty="na", partitioning="poisot") # returns NA for OS and ST
# betalink(prepare_networks(list(testarray[,,1]))[[1]], prepare_networks(list(testarray[,,2]))[[1]]) # betalink also returns NaN for this case (but requires package betalink)
betalinkr(testarray, partitioning="poisot") # fixed, now OS is zero
betalinkr(testarray, partitioning="commondenom", partition.st=TRUE) # Novotny-style: plant differences rule here
#--case2: Vazquez-data --
testarray <- webs2array(Safariland, vazarr)
# various options
# some binary examples
betalinkr(testarray)
betalinkr(testarray, partitioning="poisot", binary=TRUE, index="bray")
betalinkr(testarray, index="jaccard")
betalinkr(testarray, partitioning="poisot", binary=TRUE, index="jaccard")
# some quantitative examples
betalinkr(testarray, binary=FALSE, index="sorensen")
betalinkr(testarray, binary=FALSE, partitioning="poisot")
betalinkr(testarray, partitioning="commondenom", binary=FALSE, proportions=FALSE)
betalinkr(testarray, partitioning="poisot", binary=FALSE, proportions=FALSE)
betalinkr(testarray, index="horn", binary=F, partitioning="poisot")
# partition.st:
betalinkr(testarray, partitioning="commondenom", binary=TRUE, index="sorensen",partition.st=TRUE)
betalinkr(testarray, partitioning="commondenom", binary=FALSE, index="sorensen",partition.st=TRUE)
#--case3: two fully connected and completely shared webs --
testarray <- array(1:24, dim=c(2, 3, 2))
betalinkr(testarray)
# mostly shared webs
testarray <- array(1:24, dim=c(2, 3, 4))
set.seed(23) # creates a special case where OS is smaller for "poisot" than for "commondenom"
testarray[sample(1:24, 10)] <- 0 # setting some entries of above matrix to zero
testarray <- testarray[, , sample(1:4, 2)] # selecting two sites at random (for now, just developing the function for a 2row-matrix)
betalinkr(testarray, partitioning="poisot", binary=F)
betalinkr(testarray, partitioning="commondenom", binary=F, partition.rr=T) # warning, but shows that OS_poisot < OS_commondenom can be explained by size difference of sharedsp subwebs (OS.rich) being removed by standardization to proportions (only in poisot this is done for the subweb)
#--case4: example from Figure 1 in Poisot et al. 2012 --
metaweb <- matrix(rep(0,25),nrow=5)
metaweb[as.matrix(data.frame(c(2,4,5,5),c(1,2,2,3)))] <- 1 # the adj. matrix for the metaweb
dimnames(metaweb) <- list(letters[1:5], letters[1:5]) # creating species names
web1 <- metaweb
web1[5,2] <- 0 # one link removed from metaweb
web2 <- web1[-1,-1] # top predator removed from web1
web3 <- metaweb[-1,-1] # top predator removed from metaweb
betalinkr_multi(webs2array(web1,web2,web3),partitioning="poisot") # OS>ST (web1 vs web3)
betalinkr_multi(webs2array(web1,web2,web3), partitioning="commondenom") # OS=ST (web1 vs web3)
# partition.st:
betalinkr_multi(webs2array(web1,web2,web3), partition.st=T)
# partition.rr:
betalinkr_multi(webs2array(web1,web2,web3), partition.rr=T) # WN.rich=0, but OS.rich>0 (replacement leaves sharedspweb)
# both secondary partitions in one call
betalinkr_multi(webs2array(web1,web2,web3), partition.st=T, partition.rr=T)
# C.score
C.score(Safariland, FUN=sd, normalise=T) # check that "any" functions works!
C.score(t(Safariland))
m <- matrix(c(1,0, 0,1, 1,0, 0,1, 1,0, 0,1, 1,0), 7,2,TRUE)
C.score(t(m), normalise=FALSE)
C.score(m, normalise=FALSE)
C.score(t(m), normalise=TRUE) # should be 0.57, since half of the species have non-checkerboard distribution
C.score(m, normalise=TRUE) # should be 1!
n <- matrix(c(1,0,0, 0,1,0, 0,0,1), 3,3)
C.score(t(n), normalise=T)
system.time(C.score(memmott1999)) # 3s
# CC (closeness centrality)
CC(Safariland)
CC(Safariland, rescale=F)
wf <- as.one.mode(Safariland, project="lower", weighted=F)
wt <- as.one.mode(Safariland, project="lower", weighted=T)
closeness(wf, cmode="suminvundir")
closeness(wt, cmode="suminvundir") # makes no difference!
specieslevel(Safariland, index="closeness") # same as CC(. , rescale=T); no option for rescale=F
# compart
compart(Safariland) # a comparted network
compart(bezerra2009) # an uncomparted network
# computeModules
## a lot to test here! let's start with the problem of calling computeModules twice in a row:
comp1 <- computeModules(vazquenc)
comp2 <- computeModules(vazquenc, forceLPA=TRUE)
comp3 <- computeModules(vazquenc, method="DormannStrauss")
plotModuleWeb(comp1)
plotModuleWeb(comp2)
plotModuleWeb(comp3, weighted=F)
# to be continued ...
web <- matrix(c(0,1), 3, 3)
web[1,] <- 1
computeModules(web) # test ability to remove all-1s
# check it works with fully connecte network (error fixed in 2.09):
web <- matrix(runif(150, 0.1, 10), 30, 50)
computeModules(web)
a<-matrix(c(1,1,1,1,1,1,
1,1,1,1,1,1,
1,1,1,1,1,1,
0,1,0,0,0,0,
0,1,0,0,0,0,
0,1,0,0,0,0,
0,1,0,0,0,0,
0,1,0,0,0,0,
1,1,1,1,1,1,
1,1,0,0,0,0,
1,1,0,0,0,0), ncol=11, nrow =6)
computeModules(a)
computeModules(a, empty.web=T) # should cause an error!
slot(computeModules(a), "likelihood")
# czvalues
comp1 <- computeModules(memmott1999)
czvalues(comp1, weighted=T)
czvalues(comp1, level="lower")
# plotModuleWeb(comp1)
czvalues(comp3)
# decimalr2dtable
nulls <- decimalr2dtable(100, Safariland)
g.dec <- sapply(nulls, networklevel, index="generality")
plot(density(g.dec[1,]), xlim=c(1, 3))
# degreedistr
degreedistr(web=memmott1999)
degreedistr(web=memmott1999, pure.call=F)
degreedistr(web=memmott1999, pure.call=F, level="lower")
degreedistr(web=memmott1999, pure.call=T, level="lower")
degreedistr(web=memmott1999, pure.call=T, level="higher", las=1)
# dfun
set.seed(2)
dfun(vazquenc, abuns=runif(24, 1,9)) # checks whether external abundances are accepted
dfun(t(vazquenc), abuns=runif(7, 1,9)) # checks whether external abundances are accepted
# DIRT_LPA_wb_plus
res <- DIRT_LPA_wb_plus(Safariland, mini=3, reps=20)
mod <- convert2moduleWeb(Safariland, res)
plotModuleWeb(mod)
# discrepancy
discrepancy(vazquenc)
#nested(vazquenc, method="discrepancy2")
## Not nice, this; it's a namespace issue; somehow permute::allPerms is not available to nesteddisc, forcing me to load all of vegan here! Don't know what's going wrong.
## OUTCOMMENTED because otherwise vegan would be loaded (through nested)! That would obviously affect the check of all following functions!
replicate(10, discrepancy(vazquenc[, sample(1:24)])) # varies with sequence!
replicate(10, vegan::nesteddisc(vazquenc[, sample(1:24)])$statistic) # pre-sorts the matrix
# Check that this works, because vegan is being restructured and now has a function "nullmodel"!
nulls <- simulate(vegan::nullmodel(Safariland, method="quasiswap"), nsim = 10)
apply(nulls, 3, discrepancy)
# empty
vazquenc[,3] <- 0
empty(vazquenc, count=TRUE)
rm(vazquenc)
M <- matrix(c(0, 0, 1, 0, 1), nrow=1)
empty(M) # should be matrix with 1, 1!
# endpoint
endpoint(vazquenc)
# extinction: see also second.extinct
# fc
fc(t(Safariland), dist="canberra", method="complete")
fc(t(Safariland), dist="euc", method="single")
# frame2webs ...
# genweb
genweb(10, 20, 4)
# grouplevel
grouplevel(vazquenc)
grouplevel(vazquenc, level="higher")
grouplevel(vazquenc, level="lower", weighted=FALSE)
grouplevel(vazquenc, level="lower", weighted=TRUE, index=c("niche overlap"))
grouplevel(vazquenc, level="higher", weighted=TRUE, index=c("niche overlap", "fd", "weighted cluster coefficient"))
# H2fun
set.seed(2)
hist(sapply(nullmodel(vazquenc, 50), function(x) H2fun(x)[[1]])) # should be close to 0
H2fun(matrix(runif(100, 2, 100), 10, 10), H2_integer=FALSE)
# linklevel
str(linklevel(memmott1999, index=c("dependence", "endpoint")))
# listModuleInformation
if (!exists("comp1")) comp1 <- computeModules(vazquenc)
listModuleInformation(comp1)
# mgen
obs.mat <- matrix(c(1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,1,1,0,0,0,1,0,0,0,0), 5, 5)
rs <- rowSums(obs.mat)
cs <- colSums(obs.mat)
web <- rs %*% t(cs)
web <- web/sum(web)
n = sum(obs.mat)
mgen(web, n, keep.species=FALSE, rep.cell=FALSE) # Allowing zero marginal sums
mgen(web, n, keep.species=TRUE, rep.cell=FALSE) # Not allowing zero marginal sums
mgen(mosquin1967, keep.species=FALSE, rep.cell=TRUE) # Allowing zero marginal sums
mgen(mosquin1967, keep.species=TRUE, rep.cell=TRUE) # Not allowing zero marginal sums
# ND, BC, CC
ND(vazquenc)
BC(vazquenc)
BC(vazquenc, rescale=FALSE, weighted=FALSE)
CC(vazquenc)
# nest.smdm
nest.smdm(Safariland)
nest.smdm(Safariland, weighted=TRUE)
nest.smdm(Safariland, weighted=TRUE, decreasing="abund")
nest.smdm(Safariland, weighted=T, decreasing="abund", sort=F)
# identify modules using computeModules:
mod <- computeModules(Safariland)
const <- module2constraints(mod)
nest.smdm(Safariland, constraint=const)
nest.smdm(Safariland, constraint=const, weighted=T)
# nested
nested(vazquenc, method="ALL")
# nestedness # DEPRECATED!!
#nestedness(Safariland, n.nulls=20)[c(4, 9:20)]
#nestedness(Safariland, null.models=FALSE)$temperature
# nestedrank
nestedrank(Safariland, normalise=F)
nestedrank(Safariland, weighted=F, normalise=F)
nestedrank(Safariland, method="binmatnest")
nestedrank(Safariland, method="wine")
nestedrank(Safariland, method="wine", weighted=FALSE)
nestedrank(Safariland, method="sort")
nestedrank(Safariland, method="otto")
# networklevel
networklevel(vazquenc)
networklevel(vazquenc, index="networklevel")
networklevel(vazquenc, index="networklevel", weighted=FALSE)
networklevel(vazquenc, index="quantitative")
networklevel(vazquenc, index="H2")
networklevel(vazquenc, index=c("H2", "cluster coefficient"))
networklevel(vazquenc, legacy=TRUE)
# check that double calls to an index do work:
networklevel(matrix(rpois(16,4),nrow=4),c("H2","H2"))
networklevel(Safariland, index="NODF")
networklevel(Safariland, index="modularity")
replicate(10, networklevel(Safariland[sample(1:9), sample(1:27)], index="discrepancy")) # despite reordering ties, this is not always achieved within the 200 iterations of nesteddisc
# nodespec
nodespec(Safariland)
nodespec(Safariland, inf.replace=Inf)
# npartite ...
# nullmodel
nullmodel(motten1982, 2, "r2d")
for (i in 1:6) nullmodel(motten1982, 2, i) # i=6 should return an error message!
nullmodel(motten1982, 2, "mgen")
# null.distr
null.distr(2, vazquenc)
null.distr(2, vazquenc>0, distr="negative binomial") # tests whether it works with binary data
# null.t.test
null.t.test(vazquenc, N=30, index="connectance") # does it work with one index?
null.t.test(vazquenc, N=30, index=c("connectance", "linkage density")) # does it work with one index?
null.t.test(Safariland, index=c("generality", "vulnerability", "connectance","links per species","cluster coefficient"), nrep=4, N=20)
null.t.test(Safariland, index=c("cluster coefficient"), nrep=4, N=20)
# nullmodel
lapply(1:5, function(x) nullmodel(vazquenc, N=2, method=x))
lapply(c("r2d", "swap.web", "vaznull", "shuffle.web", "mgen"), function(x) nullmodel(vazquenc, N=2, method=x))
# PAC
PAC(vazquenc)
PAC(vazquenc>0)
# PDI
PDI(vazquenc, normalise=FALSE, log=TRUE)
PDI(vazquenc>0)
# plotmatrix
S <- sortmatrix(Safariland, topology = "nested", sort_by = "weights")
S <- sortmatrix(kato1990, topology = "nested", sort_by = "weights")
plotmatrix(S$matrix, binary=FALSE)
plotmatrix(S, binary=TRUE)
# plotModuleWeb
if (!exists("comp1")) comp1 <- computeModules(vazquenc)
plotModuleWeb(comp1)
plotModuleWeb(comp1, plotModules = TRUE, rank = TRUE, weighted = TRUE, displayAlabels = TRUE, displayBlabels = TRUE, labsize = 0.6, xlabel = "", ylabel = "", square.border = "lightgreen", fromDepth = 0, upToDepth = -1)
# plotPAC
plotPAC(PAC(vazquenc))
plotPAC(PAC(vazquenc), scaling = 2, plot.scale = 1.5, fill.col = rgb(0.2, 0.3, 0.4, 0.5), arrow.col = rgb(0.4, 0.3, 0.2, 0.5), outby = 0.5, label = F, text=TRUE, circles = T, radius = 1.5)
plotPAC(kevan1970, arrow.col=rainbow(30), text=F) # test multiple colours
plotPAC(kevan1970, arrow.col=rainbow(30), text=F, outby=.9) # test multiple colours
# plotweb
plotweb(vazquenc)
# test of Jochen's workaround:
plotweb(vazquenc,abuns.type='independent')
plotweb(Safariland, abuns.type='independent')
plotweb(Safariland, abuns.type='independent',arrow="down.center")
plotweb(Safariland, abuns.type='additional',arrow="down.center")
# an example set with abundances
myabuns.low <- rowSums(Safariland)
myabuns.low[rownames(vazquenc)] <- myabuns.low[rownames(vazquenc)] + rowSums(vazquenc) # "total abundances" (might be independent)
myabuns.low.unused <- myabuns.low - rowSums(Safariland)[names(myabuns.low)] # "unused abundances"
plotweb(Safariland, abuns.type='independent',arrow="down.center",low.abun=myabuns.low) # that's correct
plotweb(Safariland, abuns.type='additional',arrow="down.center",low.abun=myabuns.low) # that's wrong
plotweb(Safariland, abuns.type='additional',arrow="down.center",low.abun=myabuns.low.unused) # that's how it should look like for the additional case
plotweb(Safariland, abuns.type='independent',arrow="down.center",low.abun=myabuns.low*0.2) # still works
plotweb(Safariland, abuns.type='additional',arrow="down.center",low.abun=myabuns.low*0.2) # always shows marginals as abundances
plotweb(Safariland, abuns.type='independent',arrow="no",low.abun=myabuns.low*0.2) # currently gives a warning, but the ratio between upper width and lower width could actually tell you something about preferences!
# plotweb2 ...
# printoutModuleInformation
if (!exists("comp1")) comp1 <- computeModules(vazquenc)
printoutModuleInformation(comp1)
# restrictednull
Mod <- computeModules(Safariland)
Part <- module2constraints(Mod)
row.Part <- Part[1:nrow(Safariland)]
col.Part <- Part[(nrow(Safariland)+1):(nrow(Safariland)+ncol(Safariland))]
nulls <- restrictednull(web = Safariland, R.partitions = row.Part, C.partitions = col.Part)
nulls <- restrictednull(web = Safariland, Prior.Pij = "equiprobable", R.partitions = row.Part, C.partitions = col.Part)
nulls <- restrictednull(web = Safariland, conditional.level="matrix") # this should essential be vaznull, I think
nulls <- restrictednull(web = Safariland, Prior.Pij="degreeprob.byarea", conditional.level="areas", R.partitions = row.Part, C.partitions = col.Part)
# robustness
# second.extinct
bs <- second.extinct(Safariland, method="random", participant="both", details=T)
slope.bipartite(bs) # should return an error with an explanation
bs <- second.extinct(Safariland, method="random", participant="both", details=F)
slope.bipartite(bs) # should work
second.extinct(Safariland, participant="both", method="external", ext.row=1:9, ext.col=27:1) # should break!
web <- matrix(c(3, 2, 3, 0, 0, 0, 0, 1, 0, 0, 0, 1), ncol = 3)
second.extinct(web, participant = "lower", method = "abundance")
second.extinct(web, participant = "lower", method = "random")
second.extinct(web, participant = "higher", method = "abundance")
# slope.bipartite
# sortmatrix
sortmatrix(Safariland, topology="nested")
sortmatrix (Safariland, topology = "nested", sort_by = "weights")
# sortweb
# specieslevel
web <- matrix(c(0,0,0,0,0,0,0,2,0,0,1,3,1,0,5,8),nrow=4) # check for warnings (see email by Jochen 7.3.2014)
specieslevel(bezerra2009)
specieslevel(bezerra2009, index="betweenness") # lower level is all NaN (I guess because bezerra is nearly complete as one-mode?
specieslevel(Safariland, index="betweenness")
specieslevel(Safariland, index="closeness")
specieslevel(bezerra2009, level="higher", index=c("proportional similarity", "proportional generality"))
specieslevel(Safariland, index="nestedrank", nested.weighted=T)
specieslevel(Safariland, index="nestedrank", nested.weighted=F)
specieslevel(Safariland, index="nestedrank", nested.weighted=T, nested.normalise=F)
specieslevel(Safariland, index="nestedrank", nested.weighted=F, nested.normalise=F)
specieslevel(Safariland, index="nestedrank", nested.weighted=F, nested.normalise=T, nested.method="wine")
specieslevel(Safariland, index="nestedrank", nested.weighted=F, nested.normalise=F, nested.method="sort")
# from Jochen's reported errors in specieslevel:
specieslevel(matrix(rpois(16,3),nrow=4),index="ALLBUTD")
specieslevel(matrix(c(0,0,5,0,0,5,0,0,5,0,0,5),nrow=3,byrow=T),index="closeness", level="higher")
specieslevel(matrix(c(0,0,5,0,0,5,0,0,5,0,0,5),nrow=3,byrow=T),index="closeness", level="lower")
specieslevel(matrix(c(0,0,5,0,0,5,0,0,5,0,0,5),nrow=3,byrow=T),index="betweenness", level="lower")
specieslevel(matrix(c(0,0,5,0,0,5,0,0,5,0,0,5),nrow=3,byrow=T),index="betweenness", level="higher")
specieslevel(vazquec, index="interaction push pull") # from Natacha Chacoff's error report
# strength
# swap.web
# togetherness
# vaznull
set.seed(1)
m <- matrix(rpois(4, 2), 2, 2)
vaznull(2, m) # Error when m is full (i.e. no 0); works fine with a single 0 already (set seed to 4)
rowSums(vaznull(1, Safariland)[[1]])
unname(rowSums(Safariland))
# often rather large discrepancies in the number of interactions!
#vaznullexternal
abun.lower <- c(15,5,2,7,4,8,6,0.01,6)
set.seed(2)
(abun.higher <- rpois(27, lambda=4))
abun.higher[1] <- 0.001
nulls <- vaznullexternal(2, Safariland, abun.higher=abun.higher, abun.lower=abun.lower)
cor(colSums(nulls[[1]]), abun.higher) # close to 1
nulls <- vaznullexternal(2, Safariland)
cor(colSums(nulls[[1]]), colSums(Safariland)) # very close to 1
# V.ratio
# visweb
# web2edges
web2edges(Safariland)
web2edges(Safariland, both.directions=TRUE)
web2edges(as.one.mode(Safariland, project="lower"), is.one.mode=T)
# webs2array
data(Safariland, vazquenc, vazquec)
allin1 <- webs2array() # returns uninformative error
allin1 <- webs2array(Safariland) # returns informative error
allin1 <- webs2array(Safariland, vazquenc, vazquec) # just works
str(allin1)
otto <- list(Safariland, vazarr)
str(webs2array(otto, vazquec))
testfun <- function(x) webs2array(x)
str(testfun(otto)) # caused an error in the pre-2.18 version, which used only the ellipsis (...), not x.
## now we can compute distance between two webs:
vegdist(t(cbind(as.vector(allin1[,,2]), as.vector(allin1[,,3]))), method="jacc")
webinput <- substitute(list(Safariland, vazquenc, vazquec))
as.character(webinput)
# wine
#### OLD STUFF ####
## Below the testfile is the workflow on the old computer, where the compression did not work and thus several detours had to be taken.
# 0. sync vignette-folder for save-keeping with same directory one level higher (the one-level higher is the one I use for everything and only copy-paste the .Rnw into vignette before building the package).
#
# 1. build package normally (trying to compact the vignette)
R CMD build bipartite --compact-vignettes=gs+qpdf
# 2. go to some webpage and compact there the vignette from inst/doc in the built package, e.g. https://www.ilovepdf.com !!! Only if larger than 1MB !!!
...
# 3. put the thus compacted PDF into inst/doc of the development folder (not into the built!), put in there also the .R and .Rnw files from inst/doc of the just-built .tar.gz!
...
# 4. copy-paste the "build" folder of the .tar.gz of step 1 into the development folder; it contains the data and vignette reference .rdb and .rds needed for a working package!
...
# 5. Delete, in vignettes, the cache-folder and auxiliary LaTeX-files and Sweave.sty; keep only the .Rnw and the .bib, and the figures-folder (and the styles: mee.bst and Sweavel.sty)
...
# 6. build package anew without rebuilding the vignettes (and without cleaning the docs, in case you are using devtools::build!)
R CMD build bipartite --no-build-vignettes --resave-data
# 7. check all is fine: first locally, then on win-builder (https://win-builder.r-project.org/upload.aspx)
R CMD check bipartite_2.17.tar.gz --as-cran
R CMD install bipartite_2.17.tar.gz # optional; check html of help and link to vignette in RStudio
# if you get this error: Error in fetch(key) : lazy-load database '/Users/Carsten/Library/R/4.0/library/bipartite/help/bipartite.rdb' is corrupt
# re-start R (RStudio); this is just a point of the install not updating the central help pages (https://stackoverflow.com/questions/30424608/error-in-fetchkey-lazy-load-database).
## Comments on the workflow above:
## ad 0.: The vignette is a pain in the neck! The vignettes folder in the level of the top bipartite folder (in PDFetc) is the one to use for writing and processing the vignette! There are some problems, for example that in the betweenness comparison I call packages not listed in "Depends" of bipartite. Since I don't want to make bipartite dependent on packages that do not work well, I now compile the vignette in this folder with "eval=T", then copy the output for this since R-chunk from the .tex-file into the .Rnw file and set "eval=F" (there is a note to that effect in the .Rnw). Then I put the .Rnw into the vignettes-folder and the inst/doc of the package. What a mess!
## ad 1.: Somehow --compact-vignettes... does not compact at all. I tried all options (both, gs+qpdf, qpdf, gs; always without quotes!), nothing happened. I ran qpdf::pdf_compact and that did work, so qpdf is on my system(s); I have no idea what else to do.
## ad 2.: You can try
## tools::compactPDF("/Users/Carsten/Data/aktuell/Networks/bipartite/bipartite/inst/doc", qpdf=Sys.which(Sys.getenv("R_QPDF", "qpdf")), gs_quality = "ebook") ## but for me this did not yield any compression;
## ad 5.: There are other check options, e.g. rhub::check("bipartite_2.16.tar.gz", platform = "fedora-clang-devel") # requires validate_email() before first run; rhub misses some packages or package options (e.g. titlesec and nottoc in tocbibind and hidelinks in hyperref)
##
## Misc:
## * find non-UTF8 characters: find . | egrep [^a-zA-Z0-9_\.\/\-\s]
## * check link to external functions: https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Cross_002dreferences
## * if something goes wrong with the vignette build, fix and start over with the package building (it is difficult to move the right files into the right folders; R even checks the date of .Rnw files!)