diff --git a/.RData b/.RData index 54e02c4..2968deb 100644 Binary files a/.RData and b/.RData differ diff --git a/.Rhistory b/.Rhistory index 500af40..aa18fc6 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1,26 +1,3 @@ -#Simular una base de datos como la que tiene Pame -m <- matrix(rbinom(100, size = 1, prob = 0.3), ncol = 10, byrow = T) %>% as.data.frame() %>% tibble::rowid_to_column() -## Transformar en red -Mat <- network::as.network(as.matrix(m[,-1])) -Mat -Adjacency <- as.matrix.network.adjacency(Mat) -Adjacency -library(network) -library(igraph) -library(tidyverse) -set.seed(2020) -#Simular una base de datos como la que tiene Pame -m <- matrix(rbinom(100, size = 1, prob = 0.3), ncol = 10, byrow = T) %>% -as.data.frame() %>% -tibble::rowid_to_column() -View(m) -library(network) -library(tidyverse) -set.seed(2020) -#Simular una base de datos como la que tiene Pame -m <- matrix(rbinom(100, size = 1, prob = 0.3), ncol = 10, byrow = T) %>% -as.data.frame() %>% -tibble::rowid_to_column() ## Transformar en red Mat <- network::as.network(as.matrix(m[,-1])) Adjacency <- as.matrix.network.adjacency(Mat) @@ -510,3 +487,26 @@ library(NetworkExtinction) install.packages("pkgdown") install.packages("ragg") install.packages("ragg") +library(NetworkExtinction) +library(NetworkExtinction) +install.packages("cranlogs") +?cranlogs::cran_downloads() +NetExt <- cran_downloads(packages = "NetworkExtinction",from = "2014-06-30", to = "2022-11-22") +library(cranlogs) +NetExt <- cran_downloads(packages = "NetworkExtinction",from = "2014-06-30", to = "2022-11-22") +NetExt +NetExt$count +NetExt$count %>% hist +NetExt$count |> hist +NetExt$count |> hist() +NetExt$count |> sum() +sum(NetExt$count) +NetExt <- cran_downloads(packages = "NetworkExtinction", when = "last-month") +sum(NetExt$count) +View(NetExt) +NetExt <- cran_downloads(packages = "NetworkExtinction",from = "2014-06-30", to = "2022-11-22") +list.files(path = "data/") +citation("splines") +covr::code_coverage() +covr::package_coverage() +covr::package_coverage() diff --git a/.Rproj.user/shared/notebooks/paths b/.Rproj.user/shared/notebooks/paths index 9bfd029..e005ca9 100644 --- a/.Rproj.user/shared/notebooks/paths +++ b/.Rproj.user/shared/notebooks/paths @@ -1 +1,2 @@ +/home/au687614/Documents/NetworkExtinction/R/Extintions.R="5517A387" /home/au687614/Documents/NetworkExtinction/README.Rmd="BEC06318" diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..2c5bb50 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index 4f9a67a..da2efbd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,9 +16,11 @@ Imports: broom, doParallel, dplyr, foreach, ggplot2, igraph, magrittr, network, License: GPL (>= 2) Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.2 Suggests: knitr, rmarkdown, - pkgdown + pkgdown, + testthat (>= 3.0.0) VignetteBuilder: knitr +Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index e6a4163..64de460 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -44,7 +44,6 @@ importFrom(igraph,as.undirected) importFrom(igraph,cluster_edge_betweenness) importFrom(igraph,cluster_infomap) importFrom(igraph,cluster_label_prop) -importFrom(igraph,cluster_spinglass) importFrom(igraph,graph_from_adjacency_matrix) importFrom(igraph,modularity) importFrom(magrittr,"%>%") diff --git a/NetworkExtinction-report.html b/NetworkExtinction-report.html new file mode 100644 index 0000000..2e75a2c --- /dev/null +++ b/NetworkExtinction-report.html @@ -0,0 +1,6189 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + +1 | ++ |
+ #' Extinctions analysis for ecological networks+ |
+
2 | ++ |
+ #'+ |
+
3 | ++ |
+ #' The SimulateExtinctions function, can be used to test how the order of species+ |
+
4 | ++ |
+ #' extinctions, species-dependency on existing interaction strength, and rewiring potential might affect the stability of the network by comparing The extinction history+ |
+
5 | ++ |
+ #' and checking for secondary extinctions.+ |
+
6 | ++ |
+ #'+ |
+
7 | ++ |
+ #' @param Network a network representation as a an adjacency matrix, edgelist,+ |
+
8 | ++ |
+ #' or a network object+ |
+
9 | ++ |
+ #' @param Method a character with the options Mostconnected and Ordered+ |
+
10 | ++ |
+ #' @param Order a numeric vector indexing order of primary extinctions. For Method = Mostconnected Order must be NULL. If Order is not NULL, Method is internally forced to be Ordered.+ |
+
11 | ++ |
+ #' @param NetworkType a character with the options Trophic and Mutualistic - is used to calculate secondary extinctions.+ |
+
12 | ++ |
+ #' @param clust.method a character with the options cluster_edge_betweenness,+ |
+
13 | ++ |
+ #' cluster_label_prop or cluster_infomap, defaults to cluster_infomap+ |
+
14 | ++ |
+ #' @param IS either numeric or a named vector of numerics. Identifies the threshold of relative interaction strength which species require to not be considered secondarily extinct (i.e. IS = 0.3 leads to removal of all nodes which lose 70 percent of their interaction strength in the Network argument). If a named vector, names must correspond to vertex names in Network argument.+ |
+
15 | ++ |
+ #' @param Rewiring either a function or a named vector of functions. Signifies how rewiring probabilities are calculated from the RewiringDist argument. If FALSE, no rewiring is carried out.+ |
+
16 | ++ |
+ #' @param RewiringDist a numeric matrix of NxN dimension (N... number of nodes in Network). Contains, for example, phylogenetic or functional trait distances between nodes in Network which are used by the Rewiring argument to calculate rewiring probabilities. If Rewiring == function(x){x}, this matrix is expected to contain probabilities of a connection being present between species-pairs.+ |
+
17 | ++ |
+ #' @param RewiringProb a numeric which identifies the threshold at which to assume rewiring potential is met.+ |
+
18 | ++ |
+ #' @param verbose Logical. Whether to report on function progress or not.+ |
+
19 | ++ |
+ #' @return exports list containing a data frame with the characteristics of the network after every extinction and a network object containing the final network. The resulting data frame contains 11 columns that incorporate the topological index, the secondary extinctions, predation release, and total extinctions of the network in each primary extinction.+ |
+
20 | ++ |
+ #' @details When method is Mostconnected, the function takes the network and calculates which node is the most connected of the network, using total degree. Then remove the most connected node, and calculates the the topological indexes of the network and the number of secondary extinctions. This process is repeated until the entire network has gone extinct.+ |
+
21 | ++ |
+ #'+ |
+
22 | ++ |
+ #' When method is Ordered, it takes a network, and extinguishes nodes using a custom order, then it calculates the secondary extinctions and plots the accumulated secondary extinctions.+ |
+
23 | ++ |
+ #'+ |
+
24 | ++ |
+ #' When NetworkType = Trophic, secondary extinctions only occur for any predator, but not producers. If NetworkType = Mutualistic, secondary extinctions occur for all species in the network.+ |
+
25 | ++ |
+ #'+ |
+
26 | ++ |
+ #' When clust.method = cluster_edge_betweenness computes the network modularity using cluster_edge_betweenness methods from igraph to detect communities+ |
+
27 | ++ |
+ #' When clust.method = cluster_label_prop computes the network modularity using cluster_label_prop methods from igraph to detect communities+ |
+
28 | ++ |
+ #' When clust.method = cluster_infomap computes the network modularity using cluster_infomap methods from igraph to detect communities, here the number of nb.trials are equal to the network size+ |
+
29 | ++ |
+ #' @examples+ |
+
30 | ++ |
+ #' # Mostconnected example+ |
+
31 | ++ |
+ #' data("net")+ |
+
32 | ++ |
+ #' SimulateExtinctions(Network = net, Method = "Mostconnected",+ |
+
33 | ++ |
+ #' clust.method = "cluster_infomap")+ |
+
34 | ++ |
+ #'+ |
+
35 | ++ |
+ #' #first Ordered example+ |
+
36 | ++ |
+ #' data("net")+ |
+
37 | ++ |
+ #' SimulateExtinctions(Network = net, Order = c(1,2,3,4,5,6,7,8,9,10),+ |
+
38 | ++ |
+ #' Method = "Ordered" , clust.method = "cluster_infomap")+ |
+
39 | ++ |
+ #'+ |
+
40 | ++ |
+ #' #Second Ordered example+ |
+
41 | ++ |
+ #' data("net")+ |
+
42 | ++ |
+ #' SimulateExtinctions(Network = net, Order = c(2,8,9),+ |
+
43 | ++ |
+ #' Method = "Ordered", clust.method = "cluster_infomap")+ |
+
44 | ++ |
+ #'+ |
+
45 | ++ |
+ #' #Network-Dependency Example+ |
+
46 | ++ |
+ #' data("net")+ |
+
47 | ++ |
+ #' SimulateExtinctions(Network = net, Order = c(2,8), IS = 0.3,+ |
+
48 | ++ |
+ #' Method = "Ordered", clust.method = "cluster_infomap")+ |
+
49 | ++ |
+ #'+ |
+
50 | ++ |
+ #' #Rewiring+ |
+
51 | ++ |
+ #' data("net")+ |
+
52 | ++ |
+ #' data(dist)+ |
+
53 | ++ |
+ #' SimulateExtinctions(Network = net, Order = c(2,8), IS = 0.3,+ |
+
54 | ++ |
+ #' # assuming an exponential decline in rewiring potential+ |
+
55 | ++ |
+ #' # as values in RewiringDist increase+ |
+
56 | ++ |
+ #' Rewiring = function(x){1-pexp(x, rate = 1/0.5)},+ |
+
57 | ++ |
+ #' RewiringDist = dist, # distance matrix+ |
+
58 | ++ |
+ #' RewiringProb = 0.2, # low threshold for rewiring potential+ |
+
59 | ++ |
+ #' Method = "Ordered", clust.method = "cluster_infomap")+ |
+
60 | ++ |
+ #'+ |
+
61 | ++ |
+ #' #Rewiring, assuming dist contains probabilities+ |
+
62 | ++ |
+ #' #' data("net")+ |
+
63 | ++ |
+ #' data(dist)+ |
+
64 | ++ |
+ #' SimulateExtinctions(Network = net, Order = c(2,8), IS = 0.3,+ |
+
65 | ++ |
+ #' Rewiring = function(x){x}, # no changes to the RewiringDist object means+ |
+
66 | ++ |
+ #' RewiringDist = dist, RewiringProb = 0.2,+ |
+
67 | ++ |
+ #' Method = "Ordered", clust.method = "cluster_infomap")+ |
+
68 | ++ |
+ #' @importFrom dplyr desc+ |
+
69 | ++ |
+ #' @author Derek Corcoran <derek.corcoran.barrios@gmail.com>+ |
+
70 | ++ |
+ #' @author M. Isidora Ávila-Thieme <msavila@uc.cl>+ |
+
71 | ++ |
+ #' @author Erik Kusch <erik.kusch@bio.au.dk>+ |
+
72 | ++ |
+ #' @export+ |
+
73 | ++ |
+ SimulateExtinctions <- function(Network, Method, Order = NULL,+ |
+
74 | ++ |
+ NetworkType = "Trophic", clust.method = "cluster_infomap",+ |
+
75 | ++ |
+ IS = 0,+ |
+
76 | ++ |
+ Rewiring = FALSE, RewiringDist, RewiringProb = 0.5,+ |
+
77 | ++ |
+ verbose = TRUE){+ |
+
78 | +8x | +
+ Network <- .DataInit(x = Network)+ |
+
79 | +! | +
+ if(!NetworkType %in% c("Trophic", "Mutualistic")){stop("Please specify NetworkType as either 'Trophic' or 'Mutualistic'")}+ |
+
80 | ++ | + + | +
81 | +3x | +
+ if(!is.null(Order)){Method <- "Ordered"}+ |
+
82 | ++ | + + | +
83 | +8x | +
+ '%ni%'<- Negate('%in%')+ |
+
84 | +! | +
+ if(Method %ni% c("Mostconnected", "Ordered")) stop('Choose the right method. See ?SimulateExtinction.')+ |
+
85 | ++ | + + | +
86 | +8x | +
+ edgelist <- network::as.matrix.network.edgelist(Network,matrix.type="edgelist") #Prey - Predator+ |
+
87 | +8x | +
+ if(Method == "Mostconnected"){+ |
+
88 | ++ |
+ # if(NetworkType == "Trophic"){+ |
+
89 | ++ |
+ # Conected <- as.numeric(names(sort(table(edgelist[,1]), decreasing = TRUE)))+ |
+
90 | ++ |
+ # }else{+ |
+
91 | +5x | +
+ Grado <- NULL+ |
+
92 | +5x | +
+ Conected <- data.frame(ID = 1:network::network.size(Network), Grado = sna::degree(edgelist, c("total")))+ |
+
93 | +5x | +
+ Conected <- dplyr::arrange(Conected, desc(Grado))$ID+ |
+
94 | ++ |
+ # }+ |
+
95 | +5x | +
+ DF <- ExtinctionOrder(Network = Network, Order = Conected, clust.method = clust.method,+ |
+
96 | +5x | +
+ IS = IS, Rewiring = Rewiring, RewiringDist = RewiringDist,+ |
+
97 | +5x | +
+ verbose = verbose, RewiringProb = RewiringProb, NetworkType = NetworkType,+ |
+
98 | +5x | +
+ RecalcConnect = TRUE)+ |
+
99 | ++ |
+ }+ |
+
100 | +8x | +
+ if(Method == "Ordered"){+ |
+
101 | +3x | +
+ DF <- ExtinctionOrder(Network = Network, Order = Order, clust.method = clust.method,+ |
+
102 | +3x | +
+ IS = IS, Rewiring = Rewiring, RewiringDist = RewiringDist,+ |
+
103 | +3x | +
+ verbose = verbose, RewiringProb = RewiringProb, NetworkType = NetworkType)+ |
+
104 | ++ |
+ }+ |
+
105 | ++ | + + | +
106 | +8x | +
+ return(DF)+ |
+
107 | ++ |
+ }+ |
+
108 | ++ | + + | +
109 | ++ |
+ #' Extinctions analysis from custom order+ |
+
110 | ++ |
+ #'+ |
+
111 | ++ |
+ #' This function takes a network and eliminates nodes using a custom order. Subsequently, secondary extinctions are tallied up. Secondary extinction severity can be targeted by manipulating the node-dependency on network edges (IS) and node-rewiring potential upon loss of links (Rewiring).+ |
+
112 | ++ |
+ #'+ |
+
113 | ++ |
+ #' @param Network a network representation as a an adjacency matrix, edgelist, or a network object+ |
+
114 | ++ |
+ #' @param Order a numeric vector indexing order of primary extinctions. For Method = Mostconnected Order must be NULL. If Order is not NULL, Method is internally forced to be Ordered.+ |
+
115 | ++ |
+ #' @param NetworkType a character with the options Trophic and Mutualistic - is used to calculate secondary extinctions.+ |
+
116 | ++ |
+ #' @param clust.method a character with the options cluster_edge_betweenness,+ |
+
117 | ++ |
+ #' cluster_label_prop or cluster_infomap, defaults to cluster_infomap+ |
+
118 | ++ |
+ #' @param IS either numeric or a named vector of numerics. Identifies the threshold of relative interaction strength which species require to not be considered secondarily extinct (i.e. IS = 0.3 leads to removal of all nodes which lose 70percent of their interaction strength in the Network argument). If a named vector, names must correspond to vertex names in Network argument.+ |
+
119 | ++ |
+ #' @param Rewiring either a function or a named vector of functions. Signifies how rewiring probabilities are calculated from the RewiringDist argument. If FALSE, no rewiring is carried out.+ |
+
120 | ++ |
+ #' @param RewiringDist a numeric matrix of NxN dimension (N... number of nodes in Network). Contains, for example, phylogenetic or functional trait distances between nodes in Network which are used by the Rewiring argument to calculate rewiring probabilities. If Rewiring == function(x){x}, this matrix is expected to contain probabilities of a connection being present between species-pairs.+ |
+
121 | ++ |
+ #' @param RewiringProb a numeric which identifies the threshold at which to assume rewiring potential is met.+ |
+
122 | ++ |
+ #' @param verbose Logical. Whether to report on function progress or not.+ |
+
123 | ++ |
+ #' @param RecalcConnect Logical. Whether to recalculate connectedness of each node following each round of extinction simulation and subsequently update extinction order with newly mostconnected nodes.+ |
+
124 | ++ |
+ #' @return exports list containing a data frame with the characteristics of the network after every extinction and a network object containing the final network. The resulting data frame contains 11 columns that incorporate the topological index, the secondary extinctions, predation release, and total extinctions of the network in each primary extinction.+ |
+
125 | ++ |
+ #' @details When NetworkType = Trophic, secondary extinctions only occur for any predator, but not producers. If NetworkType = Mutualistic, secondary extinctions occur for all species in the network.+ |
+
126 | ++ |
+ #'+ |
+
127 | ++ |
+ #' When clust.method = cluster_edge_betweenness computes the network modularity using cluster_edge_betweenness methods from igraph to detect communities+ |
+
128 | ++ |
+ #' When clust.method = cluster_label_prop computes the network modularity using cluster_label_prop methods from igraph to detect communities+ |
+
129 | ++ |
+ #' When clust.method = cluster_infomap computes the network modularity using cluster_infomap methods from igraph to detect communities, here the number of nb.trials are equal to the network size+ |
+
130 | ++ |
+ #'+ |
+
131 | ++ |
+ #' @importFrom dplyr relocate+ |
+
132 | ++ |
+ #' @importFrom ggplot2 aes_string+ |
+
133 | ++ |
+ #' @importFrom ggplot2 geom_line+ |
+
134 | ++ |
+ #' @importFrom ggplot2 ggplot+ |
+
135 | ++ |
+ #' @importFrom ggplot2 theme_bw+ |
+
136 | ++ |
+ #' @importFrom ggplot2 xlab+ |
+
137 | ++ |
+ #' @importFrom ggplot2 ylab+ |
+
138 | ++ |
+ #' @importFrom network as.matrix.network.edgelist+ |
+
139 | ++ |
+ #' @importFrom network delete.vertices+ |
+
140 | ++ |
+ #' @importFrom network network.edgecount+ |
+
141 | ++ |
+ #' @importFrom network network.size+ |
+
142 | ++ |
+ #' @importFrom network network.density+ |
+
143 | ++ |
+ #' @importFrom network get.vertex.attribute+ |
+
144 | ++ |
+ #' @importFrom network get.edge.attribute+ |
+
145 | ++ |
+ #' @importFrom igraph as.undirected+ |
+
146 | ++ |
+ #' @importFrom igraph E+ |
+
147 | ++ |
+ #' @importFrom sna degree+ |
+
148 | ++ |
+ #' @importFrom stats complete.cases+ |
+
149 | ++ |
+ #' @importFrom network as.matrix.network.adjacency+ |
+
150 | ++ |
+ #' @importFrom igraph graph_from_adjacency_matrix+ |
+
151 | ++ |
+ #' @importFrom igraph cluster_edge_betweenness+ |
+
152 | ++ |
+ #' @importFrom igraph cluster_label_prop+ |
+
153 | ++ |
+ #' @importFrom igraph cluster_infomap+ |
+
154 | ++ |
+ #' @importFrom igraph modularity+ |
+
155 | ++ |
+ #' @importFrom stats na.omit+ |
+
156 | ++ |
+ #' @importFrom utils setTxtProgressBar+ |
+
157 | ++ |
+ #' @importFrom utils txtProgressBar+ |
+
158 | ++ |
+ #' @importFrom dplyr desc+ |
+
159 | ++ |
+ #' @author Derek Corcoran <derek.corcoran.barrios@gmail.com>+ |
+
160 | ++ |
+ #' @author M. Isidora Ávila-Thieme <msavila@uc.cl>+ |
+
161 | ++ |
+ #' @author Erik Kusch <erik.kusch@bio.au.dk>+ |
+
162 | ++ |
+ #' @export+ |
+
163 | ++ |
+ ExtinctionOrder <- function(Network, Order, NetworkType = "Trophic", clust.method = "cluster_infomap",+ |
+
164 | ++ |
+ IS = 0,+ |
+
165 | ++ |
+ Rewiring = FALSE, RewiringDist, RewiringProb = 0.5,+ |
+
166 | ++ |
+ verbose = TRUE,+ |
+
167 | ++ |
+ RecalcConnect = FALSE+ |
+
168 | ++ |
+ ){+ |
+
169 | +! | +
+ if(!NetworkType %in% c("Trophic", "Mutualistic")){stop("Please specify NetworkType as either 'Trophic' or 'Mutualistic'")}+ |
+
170 | ++ |
+ # Setting up Objects for function run ++++++++++ ++++++++++ ++++++++++ +++++++++++ |
+
171 | +129x | +
+ Link_density <- Modularity <- Grado <- NULL+ |
+
172 | +129x | +
+ Network <- .DataInit(x = Network)+ |
+
173 | +129x | +
+ edgelist <- network::as.matrix.network.edgelist(Network,matrix.type="edgelist") #Prey - Predator+ |
+
174 | +129x | +
+ Conected <- data.frame(ID = 1:network::network.size(Network), Grado = sna::degree(edgelist, c("total")))+ |
+
175 | +129x | +
+ Conected <- dplyr::arrange(Conected, desc(Grado))+ |
+
176 | +129x | +
+ Conected1 <- Order+ |
+
177 | ++ | + + | +
178 | ++ |
+ ## Interaction Strength Loss Preparations ++++++++++ +++++++++++ |
+
179 | +129x | +
+ if(length(IS )== 1){ # when the same dependency is to be applied for all species+ |
+
180 | +129x | +
+ IS <- rep(IS, network::network.size(Network)) # repeat IS argument for all species+ |
+
181 | +129x | +
+ names(IS) <- network::get.vertex.attribute(Network, "vertex.names") # assign species names to IS arguments+ |
+
182 | ++ |
+ }else{+ |
+
183 | +! | +
+ if(sum(!(network::get.vertex.attribute(Network, "vertex.names") %in% names(IS))) != 0){stop("Please ensure that the names of the nodes in your Network are matched by names of the elements in your IS argument vector.")}+ |
+
184 | ++ |
+ }+ |
+
185 | ++ |
+ ## Rewiring Preparations ++++++++++ +++++++++++ |
+
186 | +129x | +
+ if(!isFALSE(Rewiring)){ # if rewiring has been specified+ |
+
187 | +! | +
+ if(!exists("RewiringDist")){stop("To execute rewiring simulations, you need to specify the RewiringDist argument as well as the Rewiring argument.")}+ |
+
188 | +1x | +
+ diag(RewiringDist)<- NA # set diagonal to NA as one can't rewire to oneself+ |
+
189 | +1x | +
+ if(length(Rewiring) == 1){ # when the same Rewiring happen for all species+ |
+
190 | +1x | +
+ fun <- deparse1(Rewiring) # turn function into string+ |
+
191 | +1x | +
+ Rewiring <- rep(fun, network::network.size(Network)) # repeat function for each species+ |
+
192 | +1x | +
+ names(Rewiring) <- network::get.vertex.attribute(Network, "vertex.names") # assign names of species in network to rewiring functions+ |
+
193 | ++ |
+ }+ |
+
194 | +! | +
+ if(sum(!(network::get.vertex.attribute(Network, "vertex.names") %in% names(Rewiring))) != 0){stop("Please ensure that the names of the nodes in your Network are matched by names of the elements in your Rewiring argument vector.")}+ |
+
195 | ++ |
+ }+ |
+
196 | ++ | + + | +
197 | ++ |
+ # Base net calculations ++++++++++ ++++++++++ ++++++++++ +++++++++++ |
+
198 | ++ |
+ ## base interaction strengths per node ++++++++++ +++++++++++ |
+
199 | +129x | +
+ options(warn=-1) # turn warning off+ |
+
200 | +129x | +
+ Weight_mat <- net <- network::as.matrix.network.adjacency(Network, attrname = "weight")+ |
+
201 | +129x | +
+ options(warn=0) # turn warnings on+ |
+
202 | +129x | +
+ if(sum(IS) != 0){+ |
+
203 | ++ |
+ # if(sum(network::get.edge.attribute(Network, "weight"), na.rm = TRUE) == 0){+ |
+
204 | ++ |
+ # stop("Either your network does not contain any edges with weights or your network does not have the edge attribute `weight` required for calculation of extinctions based on relative interaction strength loss.")+ |
+
205 | ++ |
+ # }+ |
+
206 | +1x | +
+ netgraph <- suppressMessages(igraph::graph_from_adjacency_matrix(net, weighted = TRUE))+ |
+
207 | +1x | +
+ if(NetworkType == "Trophic"){+ |
+
208 | +1x | +
+ strengthbaseout <- igraph::strength(netgraph, mode = "out")+ |
+
209 | +1x | +
+ strengthbasein <- igraph::strength(netgraph, mode = "in")+ |
+
210 | ++ |
+ }+ |
+
211 | +1x | +
+ if(NetworkType == "Mutualistic"){+ |
+
212 | +! | +
+ strengthbasenet <- igraph::strength(netgraph)+ |
+
213 | ++ |
+ }+ |
+
214 | ++ |
+ }+ |
+
215 | ++ | + + | +
216 | ++ |
+ ## identification of producers and top predators ++++++++++ +++++++++++ |
+
217 | +129x | +
+ indegreebasenet <- sna::degree(Network, cmode = "indegree")+ |
+
218 | +129x | +
+ indegreebasenetzeros <- sum(sna::degree(Network, cmode = "indegree") == 0)+ |
+
219 | +129x | +
+ indegreetopnetzeros <- sum(sna::degree(Network, cmode = "outdegree") == 0)+ |
+
220 | +129x | +
+ Producers <- network::get.vertex.attribute(Network, "vertex.names")[sna::degree(Network, cmode = "indegree") == 0]+ |
+
221 | +129x | +
+ TopPredators <- network::get.vertex.attribute(Network, "vertex.names")[sna::degree(Network, cmode = "outdegree") == 0]+ |
+
222 | ++ | + + | +
223 | ++ |
+ ## output object ++++++++++ +++++++++++ |
+
224 | +129x | +
+ DF <- data.frame(Spp = rep(NA, length(Order)),+ |
+
225 | +129x | +
+ S = rep(NA, length(Order)),+ |
+
226 | +129x | +
+ L = rep(NA, length(Order)),+ |
+
227 | +129x | +
+ C = rep(NA, length(Order)),+ |
+
228 | +129x | +
+ Link_density = rep(NA, length(Order)),+ |
+
229 | +129x | +
+ SecExt = rep(NA,length(Order)),+ |
+
230 | +129x | +
+ Pred_release = rep(NA,length(Order)),+ |
+
231 | +129x | +
+ Iso_nodes = rep (NA,length(Order)),+ |
+
232 | +129x | +
+ Modularity = rep (NA,length(Order)))+ |
+
233 | +129x | +
+ Secundaryext <- c()+ |
+
234 | +129x | +
+ Predationrel <- c()+ |
+
235 | +129x | +
+ accExt <- c()+ |
+
236 | +129x | +
+ totalExt <- c()+ |
+
237 | +129x | +
+ FinalExt <- list()+ |
+
238 | +129x | +
+ Conected3 <- c()+ |
+
239 | ++ | + + | +
240 | ++ |
+ # Sequential extinction simulation ++++++++++ ++++++++++ ++++++++++ +++++++++++ |
+
241 | +9x | +
+ if(verbose){ProgBar <- txtProgressBar(max = length(Order), style = 3)}+ |
+
242 | +129x | +
+ for (i in 1:length(Order)){+ |
+
243 | ++ |
+ # print(i)+ |
+
244 | ++ |
+ ### creating temporary network + deleting vertices if they have been set to go extinct ++++++++++ +++++++++++ |
+
245 | +3299x | +
+ if(length(accExt)==0){ # on first iteration+ |
+
246 | +129x | +
+ Temp <- Network+ |
+
247 | +129x | +
+ DF$Spp[i] <- Conected1[i]+ |
+
248 | +129x | +
+ network::delete.vertices(Temp, c(DF$Spp[1:i]))+ |
+
249 | ++ |
+ }+ |
+
250 | +3299x | +
+ if (length(accExt)>0){ # on any subsequent iteration+ |
+
251 | +3170x | +
+ Temp <- Network+ |
+
252 | +3170x | +
+ Temp <- network::delete.vertices(Temp, c(accExt))+ |
+
253 | +3170x | +
+ edgelist <- network::as.matrix.network.edgelist(Temp,matrix.type="edgelist")+ |
+
254 | ++ | + + | +
255 | +3170x | +
+ if(RecalcConnect){+ |
+
256 | +87x | +
+ Conected2 <- data.frame(ID = 1:network::network.size(Temp), Grado = sna::degree(edgelist, c("total")))+ |
+
257 | +87x | +
+ Conected2 <- arrange(Conected2, desc(Grado))+ |
+
258 | +87x | +
+ for(j in sort(accExt)){+ |
+
259 | +1673x | +
+ Conected2$ID <- ifelse(Conected2$ID < j, Conected2$ID, Conected2$ID + 1)+ |
+
260 | ++ |
+ }+ |
+
261 | +87x | +
+ DF$Spp[i] <- Conected2$ID[1]+ |
+
262 | ++ |
+ }else{+ |
+
263 | +3083x | +
+ DF$Spp[i] <- Conected1[i]+ |
+
264 | ++ |
+ }+ |
+
265 | ++ | + + | +
266 | +3170x | +
+ Temp <- Network+ |
+
267 | +3170x | +
+ network::delete.vertices(Temp, unique(c(c(DF$Spp[1:i]),accExt)))+ |
+
268 | ++ |
+ }+ |
+
269 | ++ | + + | +
270 | ++ |
+ ## network metrics to output object ++++++++++ +++++++++++ |
+
271 | +3299x | +
+ DF$S[i] <- network::network.size(Temp)+ |
+
272 | +3299x | +
+ DF$L[i] <- network::network.edgecount(Temp)+ |
+
273 | +3299x | +
+ DF$C[i] <- network::network.density(Temp)+ |
+
274 | +3299x | +
+ DF$Link_density[i] <- DF$L[i]/DF$S[i]+ |
+
275 | ++ | + + | +
276 | ++ |
+ ## premature complete annihilation message ++++++++++ +++++++++++ |
+
277 | +3299x | +
+ if(i > 1){+ |
+
278 | +3170x | +
+ if(DF$L[i-1] == 0){+ |
+
279 | +9x | +
+ if(verbose){setTxtProgressBar(ProgBar, length(Order))}+ |
+
280 | +127x | +
+ warning(paste("Your network become completely unconnected before all primary extinctions were simulated. This happened at extinction step", i-1, "out of", length(Order)))+ |
+
281 | +127x | +
+ break+ |
+
282 | ++ |
+ }+ |
+
283 | ++ |
+ }+ |
+
284 | ++ | + + | +
285 | ++ |
+ ## calculating modularity ++++++++++ +++++++++++ |
+
286 | +3172x | +
+ Networkclass = class(Temp)+ |
+
287 | +3172x | +
+ if (Networkclass[1] == "matrix"){+ |
+
288 | +! | +
+ netgraph = igraph::graph_from_adjacency_matrix(Temp, mode = "directed", weighted = TRUE)+ |
+
289 | ++ |
+ }+ |
+
290 | +3172x | +
+ if (Networkclass[1] == "network"){+ |
+
291 | +3172x | +
+ net = network::as.matrix.network.adjacency(Temp)+ |
+
292 | +3172x | +
+ netgraph = suppressMessages(igraph::graph_from_adjacency_matrix(net, mode = "directed", weighted = TRUE))+ |
+
293 | ++ |
+ }+ |
+
294 | +3172x | +
+ if (clust.method == "cluster_edge_betweenness"){+ |
+
295 | +5x | +
+ Membership = suppressWarnings(cluster_edge_betweenness(netgraph, weights = igraph::E(+ |
+
296 | +5x | +
+ igraph::as.undirected(netgraph)+ |
+
297 | +5x | +
+ )$weight, directed = TRUE, edge.betweenness = TRUE,+ |
+
298 | +5x | +
+ merges = TRUE, bridges = TRUE, modularity = TRUE, membership = TRUE))+ |
+
299 | +3167x | +
+ }else if (clust.method == "cluster_label_prop"){+ |
+
300 | +5x | +
+ Membership = suppressWarnings(cluster_label_prop(netgraph, weights = igraph::E(igraph::as.undirected(netgraph))$weight, initial = NULL,+ |
+
301 | +5x | +
+ fixed = NULL))+ |
+
302 | +3162x | +
+ }else if (clust.method == "cluster_infomap"){+ |
+
303 | +3162x | +
+ nb.trials = network::network.size(Temp)+ |
+
304 | +3162x | +
+ Membership = suppressWarnings(igraph::cluster_infomap(igraph::as.undirected(netgraph),+ |
+
305 | +3162x | +
+ e.weights = igraph::E(+ |
+
306 | +3162x | +
+ igraph::as.undirected(netgraph)+ |
+
307 | +3162x | +
+ )$weight,+ |
+
308 | +3162x | +
+ v.weights = NULL,+ |
+
309 | +3162x | +
+ nb.trials = nb.trials,+ |
+
310 | +3162x | +
+ modularity = TRUE))+ |
+
311 | ++ | + + | +
312 | +! | +
+ } else if (clust.method == "none"){+ |
+
313 | +! | +
+ Membership = NA+ |
+
314 | +! | +
+ }else stop('Select a valid method for clustering. ?SimulateExtinction')+ |
+
315 | +3172x | +
+ DF$Modularity[i] <- Membership$modularity+ |
+
316 | ++ | + + | +
317 | ++ |
+ ## rewiring ++++++++++ +++++++++++ |
+
318 | +3172x | +
+ accExt <- unique(append(accExt, DF$Spp[1:i]))+ |
+
319 | +3172x | +
+ if(!isFALSE(Rewiring)){+ |
+
320 | ++ |
+ ### identify rewiring potential +++++++++++ |
+
321 | +36x | +
+ Rewiring_df <- data.frame(Direction = NA,+ |
+
322 | +36x | +
+ Species = NA,+ |
+
323 | +36x | +
+ NewPartner = NA,+ |
+
324 | +36x | +
+ LostPartner = NA,+ |
+
325 | +36x | +
+ IS = NA)+ |
+
326 | +36x | +
+ Rewiring_df <- na.omit(Rewiring_df)+ |
+
327 | ++ |
+ #### loop over all deleted vertices and the connections lost because of their exclusion+ |
+
328 | +36x | +
+ for(Iter_PrimaryExt in 1:length(accExt)){+ |
+
329 | ++ |
+ # Iter_PrimaryExt = 1+ |
+
330 | +794x | +
+ LostPartner <- network::get.vertex.attribute(Network, "vertex.names")[accExt[Iter_PrimaryExt]] # name of primary extinction species+ |
+
331 | +794x | +
+ LostISCol <- Weight_mat[, LostPartner] # lost interaction strength with nodes now slated for secondary extinction+ |
+
332 | +794x | +
+ LostISRow <- Weight_mat[LostPartner, ]+ |
+
333 | +794x | +
+ Lost_df <- data.frame(LostIS = c(LostISCol, LostISRow),+ |
+
334 | +794x | +
+ Direction = rep(c(1,2), c(length(LostISCol), length(LostISRow))),+ |
+
335 | +794x | +
+ names = c(names(LostISCol), names(LostISRow))+ |
+
336 | ++ |
+ )+ |
+
337 | +794x | +
+ Lost_df <- Lost_df[Lost_df$LostIS != 0, ]+ |
+
338 | +794x | +
+ if(nrow(Lost_df)!=0){+ |
+
339 | +794x | +
+ for(Iter_LostIS in 1:nrow(Lost_df)){ ## looping over all species that were linked to the current primary extinction+ |
+
340 | ++ |
+ # Iter_LostIS = 1+ |
+
341 | +22661x | +
+ if(Rewiring[which(names(Rewiring) == Lost_df$names[Iter_LostIS])] == "function (x) { x }"){+ |
+
342 | +22661x | +
+ LostPartnerSim <- eval(str2lang(Rewiring[which(names(Rewiring) == Lost_df$names[Iter_LostIS])]))(RewiringDist[,Lost_df$names[Iter_LostIS]]) # probability of rewiring to each node+ |
+
343 | ++ |
+ }else{+ |
+
344 | +! | +
+ LostPartnerSim <- eval(str2lang(Rewiring[which(names(Rewiring) == Lost_df$names[Iter_LostIS])]))(RewiringDist[,LostPartner]) # probability of rewiring to each node in network given rewiring function and species similraity+ |
+
345 | ++ |
+ }+ |
+
346 | +22661x | +
+ names(LostPartnerSim) <- colnames(RewiringDist)+ |
+
347 | +22661x | +
+ RewiringCandidates <- LostPartnerSim[LostPartnerSim > RewiringProb & names(LostPartnerSim) %in% network::get.vertex.attribute(Temp, "vertex.names")] # rewiring probability for nodes still in temporary network and having a higher rewiring probability than 0.5+ |
+
348 | +22661x | +
+ RewiredPartner <- names(which.max(RewiringCandidates)) # most likely rewiring partner+ |
+
349 | +22661x | +
+ if(!is.null(RewiredPartner)){ # if a rewired partner has been found+ |
+
350 | +523x | +
+ Rewiring_df <- rbind(Rewiring_df,+ |
+
351 | +523x | +
+ data.frame(Direction = Lost_df$Direction[Iter_LostIS],+ |
+
352 | +523x | +
+ Species = Lost_df$names[Iter_LostIS],+ |
+
353 | +523x | +
+ NewPartner = RewiredPartner,+ |
+
354 | +523x | +
+ LostPartner = LostPartner,+ |
+
355 | +523x | +
+ IS = Lost_df$LostIS[Iter_LostIS])+ |
+
356 | ++ |
+ )+ |
+
357 | ++ |
+ }+ |
+
358 | ++ |
+ }+ |
+
359 | ++ |
+ }+ |
+
360 | ++ |
+ }+ |
+
361 | ++ | + + | +
362 | ++ |
+ ### shift rewired interaction strengths +++++++++++ |
+
363 | +36x | +
+ if(nrow(Rewiring_df) != 0){+ |
+
364 | ++ |
+ #### shift interaction weights in Weight_mat+ |
+
365 | +34x | +
+ for(Iter_Rewiring in 1:nrow(Rewiring_df)){+ |
+
366 | ++ |
+ # Iter_Rewiring = 1+ |
+
367 | ++ |
+ ## assigning shifted interaction strength+ |
+
368 | +523x | +
+ ColSpec <- Rewiring_df[Iter_Rewiring,4-Rewiring_df[Iter_Rewiring,"Direction"]]+ |
+
369 | +523x | +
+ RowSpec <- Rewiring_df[Iter_Rewiring,1+Rewiring_df[Iter_Rewiring,"Direction"]]+ |
+
370 | +523x | +
+ Weight_mat[RowSpec, ColSpec] <- Weight_mat[RowSpec, ColSpec] + Rewiring_df[Iter_Rewiring,"IS"]+ |
+
371 | ++ |
+ ## deleting shiften interaction strength+ |
+
372 | ++ | + + | +
373 | +523x | +
+ ColLost <- ifelse(Rewiring_df[Iter_Rewiring, "Direction"] == 1,+ |
+
374 | +523x | +
+ Rewiring_df[Iter_Rewiring, "LostPartner"],+ |
+
375 | +523x | +
+ Rewiring_df[Iter_Rewiring, "Species"])+ |
+
376 | +523x | +
+ RowLost <- ifelse(Rewiring_df[Iter_Rewiring, "Direction"] == 1,+ |
+
377 | +523x | +
+ Rewiring_df[Iter_Rewiring, "Species"],+ |
+
378 | +523x | +
+ Rewiring_df[Iter_Rewiring, "LostPartner"])+ |
+
379 | +523x | +
+ Weight_mat[RowLost, ColLost] <- 0+ |
+
380 | ++ |
+ }+ |
+
381 | ++ |
+ #### establishing rewired network and deleting primary extinction nodes+ |
+
382 | +34x | +
+ Network <- as.network(Weight_mat, matrix.type = "adjacency", ignore.eval=FALSE, names.eval='weight')+ |
+
383 | +34x | +
+ Temp <- Network+ |
+
384 | +34x | +
+ network::delete.vertices(Temp, unique(c(c(DF$Spp[1:i]),accExt)))+ |
+
385 | ++ |
+ }+ |
+
386 | ++ |
+ }+ |
+
387 | ++ | + + | +
388 | ++ |
+ ## identify secondary extinctions ++++++++++ +++++++++++ |
+
389 | ++ |
+ ### Relative Interaction Strength loss +++++++++++ |
+
390 | +3172x | +
+ if(sum(IS) == 0){+ |
+
391 | +3141x | +
+ SecundaryextNames <- network::get.vertex.attribute(Temp, "vertex.names")[which(sna::degree(Temp) == 0)]+ |
+
392 | +3141x | +
+ Secundaryext <- match(SecundaryextNames, network::get.vertex.attribute(Network, "vertex.names"))+ |
+
393 | ++ |
+ }else{+ |
+
394 | +31x | +
+ if(NetworkType == "Trophic"){+ |
+
395 | +31x | +
+ AbsISin <- igraph::strength(suppressMessages(igraph::graph_from_adjacency_matrix(+ |
+
396 | +31x | +
+ network::as.matrix.network.adjacency(Temp, attrname = "weight"),+ |
+
397 | +31x | +
+ weighted = TRUE)+ |
+
398 | +31x | +
+ ), mode = "in")+ |
+
399 | +31x | +
+ RelISRemainIn <- AbsISin / strengthbasein[names(strengthbasein) %in% network::get.vertex.attribute(Temp, "vertex.names")]+ |
+
400 | +31x | +
+ SecundaryextNames <- names(which(AbsISin == 0 | RelISRemainIn < IS[match(names(RelISRemainIn), names(IS))]))+ |
+
401 | +31x | +
+ SecundaryextNames <- SecundaryextNames[!(SecundaryextNames %in% Producers)]+ |
+
402 | +31x | +
+ Secundaryext <- match(SecundaryextNames, network::get.vertex.attribute(Network, "vertex.names"))+ |
+
403 | ++ |
+ }+ |
+
404 | ++ | + + | +
405 | +31x | +
+ if(NetworkType == "Mutualistic"){+ |
+
406 | +! | +
+ AbsIS <- igraph::strength(suppressMessages(igraph::graph_from_adjacency_matrix(+ |
+
407 | +! | +
+ network::as.matrix.network.adjacency(Temp, attrname = "weight"),+ |
+
408 | +! | +
+ weighted = TRUE)+ |
+
409 | ++ |
+ ))+ |
+
410 | +! | +
+ RelISloss <- AbsIS / strengthbasenet[names(strengthbasenet) %in% network::get.vertex.attribute(Temp, "vertex.names")]+ |
+
411 | +! | +
+ SecundaryextNames <- names(which(AbsIS == 0 | RelISloss < IS[match(names(RelISloss), names(IS))]))+ |
+
412 | +! | +
+ Secundaryext <- match(SecundaryextNames, network::get.vertex.attribute(Network, "vertex.names"))+ |
+
413 | ++ |
+ }+ |
+
414 | ++ |
+ }+ |
+
415 | ++ | + + | +
416 | ++ |
+ ### for trophic networks +++++++++++ |
+
417 | +3172x | +
+ if(NetworkType == "Trophic"){+ |
+
418 | +3172x | +
+ MidPredExt <- network::get.vertex.attribute(Temp, "vertex.names")[sna::degree(Temp, cmode = "indegree") == 0]+ |
+
419 | +3172x | +
+ MidPredExt <- match(MidPredExt[!(MidPredExt %in% Producers)], network::get.vertex.attribute(Network, "vertex.names"))+ |
+
420 | +3172x | +
+ SecundaryextTrue <- unique(c(SecundaryextNames[!(SecundaryextNames %in% as.character(Producers))],+ |
+
421 | +3172x | +
+ MidPredExt))+ |
+
422 | +3172x | +
+ Secundaryext <- match(SecundaryextTrue, network::get.vertex.attribute(Network, "vertex.names"))+ |
+
423 | +3172x | +
+ DF$SecExt[i] <- length(Secundaryext)+ |
+
424 | +3172x | +
+ DF$Pred_release[i] <- length(SecundaryextNames[!(SecundaryextNames %in% as.character(TopPredators))])+ |
+
425 | ++ |
+ }+ |
+
426 | ++ |
+ ### for mutualistic networks +++++++++++ |
+
427 | +3172x | +
+ if(NetworkType == "Mutualistic"){+ |
+
428 | +! | +
+ DF$SecExt[i] <- length(Secundaryext)+ |
+
429 | ++ |
+ }+ |
+
430 | +3172x | +
+ DF$Iso_nodes[i] <- sum(sna::degree(Temp) == 0)+ |
+
431 | ++ | + + | +
432 | ++ |
+ ## Return of objects ++++++++++ +++++++++++ |
+
433 | +3172x | +
+ FinalExt[[i]] <- Secundaryext+ |
+
434 | +3172x | +
+ accExt <- append(accExt, DF$Spp[1:i])+ |
+
435 | +3172x | +
+ accExt <- unique(append(accExt,Secundaryext))+ |
+
436 | +107x | +
+ if(verbose){setTxtProgressBar(ProgBar, i)}+ |
+
437 | ++ | + + | +
438 | ++ |
+ ## final Temp deletion ++++++++++ +++++++++++ |
+
439 | +3172x | +
+ if(length(accExt)>0){+ |
+
440 | +3172x | +
+ Temp <- Network+ |
+
441 | +3172x | +
+ Temp <- network::delete.vertices(Temp, c(accExt))+ |
+
442 | +3172x | +
+ edgelist <- network::as.matrix.network.edgelist(Temp,matrix.type="edgelist")+ |
+
443 | ++ |
+ # DF$Spp[i] <- Conected1[i]+ |
+
444 | +3172x | +
+ Temp <- Network+ |
+
445 | +3172x | +
+ network::delete.vertices(Temp, unique(c(c(DF$Spp[1:i]),accExt)))+ |
+
446 | ++ |
+ }+ |
+
447 | ++ |
+ }+ |
+
448 | ++ | + + | +
449 | ++ |
+ # return of final data objects ++++++++++ +++++++++++ |
+
450 | +129x | +
+ DF <- DF[!is.na(DF$Spp),]+ |
+
451 | +129x | +
+ DF$AccSecExt <- cumsum(DF$SecExt)+ |
+
452 | +129x | +
+ DF$NumExt <- 1:nrow(DF)+ |
+
453 | +129x | +
+ DF$TotalExt <- DF$AccSecExt + DF$NumExt+ |
+
454 | +129x | +
+ DF <- relocate(DF, Modularity, .after = Link_density)+ |
+
455 | +129x | +
+ class(DF) <- c("data.frame", "SimulateExt")+ |
+
456 | ++ | + + | +
457 | +129x | +
+ return(list(sims = DF,+ |
+
458 | +129x | +
+ Network = Temp))+ |
+
459 | ++ |
+ }+ |
+
460 | ++ | + + | +
461 | ++ |
+ #' Random extinction+ |
+
462 | ++ |
+ #'+ |
+
463 | ++ |
+ #' Generates a null model by generating random extinction histories and calculating the mean and standard deviation of the accumulated secondary extinctions developed by making n random extinction histories.+ |
+
464 | ++ |
+ #'+ |
+
465 | ++ |
+ #' @param Network a network representation as a an adjacency matrix, edgelist,+ |
+
466 | ++ |
+ #' or a network object+ |
+
467 | ++ |
+ #' @param nsim numeric, number of simulations+ |
+
468 | ++ |
+ #' @param Record logical, if TRUE, records every simulation and you can read the+ |
+
469 | ++ |
+ #' raw results in the object FullSims+ |
+
470 | ++ |
+ #' @param plot logical if TRUE, will add a graph to the results+ |
+
471 | ++ |
+ #' @param SimNum numeric, how many nodes to register for primary extinction. By default sets all of them.+ |
+
472 | ++ |
+ #' @param NetworkType a character with the options Trophic and Mutualistic - is used to calculate secondary extinctions.+ |
+
473 | ++ |
+ #' @param clust.method a character with the options cluster_edge_betweenness,+ |
+
474 | ++ |
+ #' cluster_label_prop or cluster_infomap, defaults to cluster_infomap+ |
+
475 | ++ |
+ #' @param parallel if TRUE, it will use parallel procesing, if FALSE (default) it will run+ |
+
476 | ++ |
+ #' sequentially+ |
+
477 | ++ |
+ #' @param ncores numeric, number of cores to use if using parallel procesing+ |
+
478 | ++ |
+ #' @param IS either numeric or a named vector of numerics. Identifies the threshold of relative interaction strength which species require to not be considered secondarily extinct (i.e. IS = 0.3 leads to removal of all nodes which lose 70 precent of their interaction strength in the Network argument). If a named vector, names must correspond to vertex names in Network argument.+ |
+
479 | ++ |
+ #' @param Rewiring either a function or a named vector of functions. Signifies how rewiring probabilities are calculated from the RewiringDist argument. If FALSE, no rewiring is carried out.+ |
+
480 | ++ |
+ #' @param RewiringDist a numeric matrix of NxN dimension (N... number of nodes in Network). Contains, for example, phylogenetic or functional trait distances between nodes in Network which are used by the Rewiring argument to calculate rewiring probabilities. If Rewiring == function(x){x}, this matrix is expected to contain probabilities of a connection being present between species-pairs.+ |
+
481 | ++ |
+ #' @param RewiringProb a numeric which identifies the threshold at which to assume rewiring potential is met.+ |
+
482 | ++ |
+ #' @param verbose Logical. Whether to report on function progress or not.+ |
+
483 | ++ |
+ #' @return exports list containing a data frame with the characteristics of the network after every extinction, a network object containing the final network, and a graph with the mean and 95percent interval. The resulting data frame contains 11 columns that incorporate the topological index, the secondary extinctions, predation release, and total extinctions of the network in each primary extinction.+ |
+
484 | ++ |
+ #' @details When NetworkType = Trophic, secondary extinctions only occur for any predator, but not producers. If NetworkType = Mutualistic, secondary extinctions occur for all species in the network.+ |
+
485 | ++ |
+ #'+ |
+
486 | ++ |
+ #' When clust.method = cluster_edge_betweenness computes the network modularity using cluster_edge_betweenness methods from igraph to detect communities+ |
+
487 | ++ |
+ #' When clust.method = cluster_label_prop computes the network modularity using cluster_label_prop methods from igraph to detect communities+ |
+
488 | ++ |
+ #' When clust.method = cluster_infomap computes the network modularity using cluster_infomap methods from igraph to detect communities, here the number of nb.trials are equal to the network size+ |
+
489 | ++ |
+ #'+ |
+
490 | ++ |
+ #' @examples+ |
+
491 | ++ |
+ #' #first example+ |
+
492 | ++ |
+ #' \dontrun{+ |
+
493 | ++ |
+ #' data("More_Connected")+ |
+
494 | ++ |
+ #' RandomExtinctions(Network = More_Connected, nsim = 20)+ |
+
495 | ++ |
+ #'+ |
+
496 | ++ |
+ #' # Using parallel procesing+ |
+
497 | ++ |
+ #' ## Detect your number of cores divide by 2+ |
+
498 | ++ |
+ #'+ |
+
499 | ++ |
+ #' cores <- ceiling(parallel::detectCores()/2)+ |
+
500 | ++ |
+ #'+ |
+
501 | ++ |
+ #' RandomExtinctions(Network = More_Connected, nsim = 20, parallel = TRUE, ncores = cores)+ |
+
502 | ++ |
+ #' }+ |
+
503 | ++ |
+ #'+ |
+
504 | ++ |
+ #' @importFrom doParallel registerDoParallel+ |
+
505 | ++ |
+ #' @importFrom dplyr group_by+ |
+
506 | ++ |
+ #' @importFrom dplyr mutate+ |
+
507 | ++ |
+ #' @importFrom dplyr summarise+ |
+
508 | ++ |
+ #' @importFrom foreach `%dopar%`+ |
+
509 | ++ |
+ #' @importFrom foreach foreach+ |
+
510 | ++ |
+ #' @importFrom ggplot2 aes_string+ |
+
511 | ++ |
+ #' @importFrom ggplot2 geom_line+ |
+
512 | ++ |
+ #' @importFrom ggplot2 geom_ribbon+ |
+
513 | ++ |
+ #' @importFrom ggplot2 ggplot+ |
+
514 | ++ |
+ #' @importFrom ggplot2 theme_bw+ |
+
515 | ++ |
+ #' @importFrom ggplot2 scale_fill_manual+ |
+
516 | ++ |
+ #' @importFrom ggplot2 xlab+ |
+
517 | ++ |
+ #' @importFrom ggplot2 ylab+ |
+
518 | ++ |
+ #' @importFrom magrittr "%>%"+ |
+
519 | ++ |
+ #' @importFrom network network.size+ |
+
520 | ++ |
+ #' @importFrom parallel makeCluster+ |
+
521 | ++ |
+ #' @importFrom parallel stopCluster+ |
+
522 | ++ |
+ #' @importFrom parallel clusterExport+ |
+
523 | ++ |
+ #' @importFrom scales muted+ |
+
524 | ++ |
+ #' @importFrom stats sd+ |
+
525 | ++ |
+ #' @importFrom stats na.omit+ |
+
526 | ++ |
+ #' @importFrom utils setTxtProgressBar+ |
+
527 | ++ |
+ #' @importFrom utils txtProgressBar+ |
+
528 | ++ |
+ #' @author Derek Corcoran <derek.corcoran.barrios@gmail.com>+ |
+
529 | ++ |
+ #' @author M. Isidora Ávila-Thieme <msavila@uc.cl>+ |
+
530 | ++ |
+ #' @author Erik Kusch <erik.kusch@bio.au.dk>+ |
+
531 | ++ |
+ #' @export+ |
+
532 | ++ |
+ RandomExtinctions <- function(Network, nsim = 10,+ |
+
533 | ++ |
+ Record = FALSE, plot = FALSE,+ |
+
534 | ++ |
+ SimNum = NULL,+ |
+
535 | ++ |
+ NetworkType = "Trophic", clust.method = "cluster_infomap",+ |
+
536 | ++ |
+ parallel = FALSE, ncores,+ |
+
537 | ++ |
+ IS = 0,+ |
+
538 | ++ |
+ Rewiring = FALSE, RewiringDist = NULL, RewiringProb = 0.5,+ |
+
539 | ++ |
+ verbose = TRUE){+ |
+
540 | +! | +
+ if(!NetworkType %in% c("Trophic", "Mutualistic")){stop("Please specify NetworkType as either 'Trophic' or 'Mutualistic'")}+ |
+
541 | ++ |
+ ## setting up objects+ |
+
542 | +2x | +
+ NumExt <- sd <- AccSecExt <- AccSecExt_95CI <- AccSecExt_mean <- Lower <- NULL+ |
+
543 | +2x | +
+ network <- .DataInit(x = Network)+ |
+
544 | +2x | +
+ if(is.null(SimNum)){+ |
+
545 | +2x | +
+ SimNum <- network::network.size(network)+ |
+
546 | ++ |
+ }+ |
+
547 | ++ | + + | +
548 | ++ |
+ ## simulations+ |
+
549 | +2x | +
+ if(verbose){ProgBar <- txtProgressBar(max = nsim, style = 3)}+ |
+
550 | +2x | +
+ if(parallel){+ |
+
551 | +! | +
+ cl <- makeCluster(ncores)+ |
+
552 | +! | +
+ registerDoParallel(cl)+ |
+
553 | +! | +
+ parallel::clusterExport(cl,+ |
+
554 | +! | +
+ varlist = c("network", "SimNum", "IS", "Rewiring", "RewiringDist", "RewiringProb"),+ |
+
555 | +! | +
+ envir = environment()+ |
+
556 | ++ |
+ )+ |
+
557 | +! | +
+ sims <- foreach(i=1:nsim, .packages = "NetworkExtinction")%dopar%{+ |
+
558 | +! | +
+ sims <- try(ExtinctionOrder(Network = network, Order = sample(1:network::network.size(network), size = SimNum),+ |
+
559 | +! | +
+ IS = IS, NetworkType = NetworkType,+ |
+
560 | +! | +
+ Rewiring = Rewiring, RewiringDist = RewiringDist,+ |
+
561 | +! | +
+ verbose = FALSE, RewiringProb = RewiringProb), silent = TRUE)+ |
+
562 | +! | +
+ try({sims$simulation <- i}, silent = TRUE)+ |
+
563 | +! | +
+ sims+ |
+
564 | ++ |
+ }+ |
+
565 | +! | +
+ stopCluster(cl)+ |
+
566 | ++ |
+ }else{+ |
+
567 | +2x | +
+ sims <- list()+ |
+
568 | +2x | +
+ for(i in 1:nsim){+ |
+
569 | +120x | +
+ sims[[i]] <- try(ExtinctionOrder(Network = network, Order = sample(1:network::network.size(network), size = SimNum),+ |
+
570 | +120x | +
+ IS = IS, NetworkType = NetworkType,+ |
+
571 | +120x | +
+ Rewiring = Rewiring, RewiringDist = RewiringDist,+ |
+
572 | +120x | +
+ verbose = FALSE, RewiringProb = RewiringProb), silent = TRUE)+ |
+
573 | +120x | +
+ try({sims[[i]]$simulation <- i}, silent = TRUE)+ |
+
574 | +120x | +
+ if(verbose){setTxtProgressBar(ProgBar, i)}+ |
+
575 | ++ |
+ }+ |
+
576 | ++ |
+ }+ |
+
577 | ++ | + + | +
578 | ++ |
+ ## extract objects+ |
+
579 | +2x | +
+ temps <- lapply(sims, "[[", 2)+ |
+
580 | +2x | +
+ sims <- lapply(sims, "[[", 1)+ |
+
581 | +2x | +
+ cond <- sapply(sims, function(x) "data.frame" %in% class(x))+ |
+
582 | +2x | +
+ cond <- c(1:length(cond))[cond]+ |
+
583 | +2x | +
+ sims <- sims[cond]+ |
+
584 | +2x | +
+ sims <- do.call(rbind, sims)+ |
+
585 | +2x | +
+ if(Record == TRUE){+ |
+
586 | +! | +
+ FullSims <- sims+ |
+
587 | ++ |
+ }+ |
+
588 | ++ | + + | +
589 | +2x | +
+ sims <- sims[!is.na(sims$SecExt), ] %>% dplyr::group_by(NumExt) %>% summarise(AccSecExt_95CI = 1.96*sd(AccSecExt), AccSecExt_mean = mean(AccSecExt)) %>% mutate(Upper = AccSecExt_mean + AccSecExt_95CI, Lower = AccSecExt_mean - AccSecExt_95CI, Lower = ifelse(Lower < 0, 0, Lower))+ |
+
590 | ++ | + + | +
591 | ++ |
+ ## plot output+ |
+
592 | +2x | +
+ if(plot == TRUE){+ |
+
593 | +! | +
+ g <- ggplot(sims, aes_string(x = "NumExt", y = "AccSecExt_mean")) + geom_ribbon(aes_string(ymin = "Lower", ymax = "Upper"), fill = scales::muted("red")) + geom_line() + ylab("Acc. Secondary extinctions") + xlab("Primary extinctions") + theme_bw()+ |
+
594 | +! | +
+ print(g)+ |
+
595 | ++ |
+ }+ |
+
596 | ++ | + + | +
597 | ++ |
+ ## object output+ |
+
598 | +2x | +
+ if(Record == T & plot == T){+ |
+
599 | +! | +
+ return(list(sims = sims, graph = g, FullSims = FullSims, nets = temps))+ |
+
600 | +2x | +
+ }else if(Record == F & plot == T){+ |
+
601 | +! | +
+ return(list(sims = sims, graph = g, nets = temps))+ |
+
602 | +2x | +
+ }else if(Record == F & plot == F){+ |
+
603 | +2x | +
+ return(list(sims = sims, nets = temps))+ |
+
604 | +! | +
+ }else if(Record == T & plot == F){+ |
+
605 | +! | +
+ return(list(sims = sims, FullSims = FullSims, nets= temps))+ |
+
606 | ++ |
+ }+ |
+
607 | ++ |
+ }+ |
+
608 | ++ | + + | +
609 | ++ |
+ #' Comparison of Null hypothesis with other extinction histories+ |
+
610 | ++ |
+ #'+ |
+
611 | ++ |
+ #' It compares an object generated either by the Mostconnected or ExtinctionOrder functions+ |
+
612 | ++ |
+ #' with a null hypothesis generated by the RandomExtinctions function it is important that+ |
+
613 | ++ |
+ #' RandomExtinctions is in plot = T.+ |
+
614 | ++ |
+ #'+ |
+
615 | ++ |
+ #' @param Nullmodel an object generated by the RandomExtinctions+ |
+
616 | ++ |
+ #' @param Hypothesis Extinction history generated by the Mostconnected or ExtinctionOrder+ |
+
617 | ++ |
+ #' fuction+ |
+
618 | ++ |
+ #' @return a plot comparing the expected value of secondary extinctions originated at random+ |
+
619 | ++ |
+ #' with the observed extinction history.+ |
+
620 | ++ |
+ #'+ |
+
621 | ++ |
+ #' @examples+ |
+
622 | ++ |
+ #' \dontrun{+ |
+
623 | ++ |
+ #' data("Less_Connected")+ |
+
624 | ++ |
+ #' History <- SimulateExtinctions(Network = Less_Connected, Method = "Mostconnected")+ |
+
625 | ++ |
+ #' NullHyp <- RandomExtinctions(Network = Less_Connected, nsim = 100)+ |
+
626 | ++ |
+ #' CompareExtinctions(Nullmodel = NullHyp, Hypothesis = History)+ |
+
627 | ++ |
+ #' }+ |
+
628 | ++ |
+ #' @importFrom broom tidy+ |
+
629 | ++ |
+ #' @importFrom ggplot2 aes+ |
+
630 | ++ |
+ #' @importFrom ggplot2 geom_line+ |
+
631 | ++ |
+ #' @importFrom ggplot2 geom_point+ |
+
632 | ++ |
+ #' @importFrom ggplot2 geom_ribbon+ |
+
633 | ++ |
+ #' @importFrom ggplot2 scale_color_manual+ |
+
634 | ++ |
+ #' @importFrom ggplot2 theme_bw+ |
+
635 | ++ |
+ #' @importFrom scales muted+ |
+
636 | ++ |
+ #' @author Derek Corcoran <derek.corcoran.barrios@gmail.com>+ |
+
637 | ++ |
+ #' @author M. Isidora Ávila-Thieme <msavila@uc.cl>+ |
+
638 | ++ |
+ #' @export+ |
+
639 | ++ | + + | +
640 | ++ |
+ CompareExtinctions <- function(Nullmodel, Hypothesis){+ |
+
641 | +1x | +
+ if(class(Hypothesis$sims)[2] == "SimulateExt"){+ |
+
642 | +1x | +
+ NumExt <- sd <- AccSecExt <- AccSecExt_mean <-NULL+ |
+
643 | +1x | +
+ if(class(Nullmodel$sims)[1] == "list"){+ |
+
644 | +! | +
+ g <- Nullmodel$graph + geom_line(aes(color = "blue"))+ |
+
645 | +! | +
+ g <- g + geom_point(data = Hypothesis, aes(y = AccSecExt), color = "black") + geom_line(data = Hypothesis, aes(y = AccSecExt, color = "black")) + scale_color_manual(name = "Comparison",values =c("black", "blue"), label = c("Observed","Null hypothesis"))+ |
+
646 | ++ |
+ } else {+ |
+
647 | +1x | +
+ g <- ggplot(Nullmodel$sims, aes(x = NumExt, y = AccSecExt_mean)) + geom_ribbon(aes_string(ymin = "Lower", ymax = "Upper"), fill = scales::muted("red")) + geom_line(color = "blue") + ylab("Acc. Secondary extinctions") + xlab("Primary extinctions") + theme_bw()+ |
+
648 | +1x | +
+ g <- g + geom_point(data = Hypothesis$sims, aes(y = AccSecExt), color = "black") + geom_line(data = Hypothesis$sims, aes(y = AccSecExt, color = "black")) + scale_color_manual(name = "Comparison",values =c("black", "blue"), label = c("Observed","Null hypothesis"))+ |
+
649 | +1x | +
+ g+ |
+
650 | ++ |
+ }+ |
+
651 | ++ | + + | +
652 | +1x | +
+ g+ |
+
653 | ++ | + + | +
654 | +1x | +
+ return(g)+ |
+
655 | ++ |
+ }+ |
+
656 | +! | +
+ if(class(Hypothesis$sims)[2] %in% c("Mostconnected", "ExtinctionOrder")){+ |
+
657 | +! | +
+ NumExt <- sd <- AccSecExt <- AccSecExt_mean <-NULL+ |
+
658 | +! | +
+ g <- Nullmodel$graph + geom_line(aes(color = "blue"))+ |
+
659 | +! | +
+ g <- g + geom_point(data = Hypothesis, aes(y = AccSecExt), color = "black") + geom_line(data = Hypothesis, aes(y = AccSecExt, color = "black")) + scale_color_manual(name = "Comparison", values =c("black", "blue"), label = c("Observed","Null hypothesis"))+ |
+
660 | +! | +
+ g+ |
+
661 | +! | +
+ return(g)+ |
+
662 | ++ |
+ }+ |
+
663 | ++ |
+ else{+ |
+
664 | +! | +
+ message("Hypothesis not of class Mostconnected or ExtinctionOrder")+ |
+
665 | ++ |
+ }+ |
+
666 | ++ |
+ }+ |
+
1 | ++ |
+ #' Degree distribution of the network+ |
+
2 | ++ |
+ #'+ |
+
3 | ++ |
+ #' This function calculates the degree distribution of the network. First it+ |
+
4 | ++ |
+ #' fits exponential, power law and truncated power law distribution models,+ |
+
5 | ++ |
+ #' and calculates the AIC values to select the best fit, and finally it plots+ |
+
6 | ++ |
+ #' the degree distribution in a log log scale showing the three fitted models+ |
+
7 | ++ |
+ #' mentioned above against the observed distribution.+ |
+
8 | ++ |
+ #'+ |
+
9 | ++ |
+ #'+ |
+
10 | ++ |
+ #' @param Network a trophic network of class network+ |
+
11 | ++ |
+ #' @param scale a character stating if the graph is on a log-log scale+ |
+
12 | ++ |
+ #' ("LogLog") or arithmetic scale ("arithmetic"), defaults to arithmetic+ |
+
13 | ++ |
+ #' @return exports three principal results:+ |
+
14 | ++ |
+ #' 1. A list with network degree distribution values and with the value of each fit model+ |
+
15 | ++ |
+ #' 2. A list with each model results and AIC of the distribution models+ |
+
16 | ++ |
+ #' 3. A Ghraph of the degree distribution with the models adjust+ |
+
17 | ++ |
+ #' In DDvalues, k represent the degree of the network and cumulative+ |
+
18 | ++ |
+ #' the probability that each specie could be have this degree (pk).+ |
+
19 | ++ |
+ #' Observation: In the graph, the zero values are not represented but this result are incorporate in the DF result+ |
+
20 | ++ |
+ #'+ |
+
21 | ++ |
+ #'@examples+ |
+
22 | ++ |
+ #'library(NetworkExtinction)+ |
+
23 | ++ |
+ #'data("chilean_intertidal")+ |
+
24 | ++ |
+ #'DegreeDistribution(chilean_intertidal)+ |
+
25 | ++ |
+ #'+ |
+
26 | ++ |
+ #'@importFrom sna degree+ |
+
27 | ++ |
+ #'@importFrom stats nls+ |
+
28 | ++ |
+ #'@importFrom broom augment+ |
+
29 | ++ |
+ #'@importFrom broom glance+ |
+
30 | ++ |
+ #'@importFrom dplyr arrange+ |
+
31 | ++ |
+ #'@importFrom dplyr bind_rows+ |
+
32 | ++ |
+ #'@importFrom dplyr case_when+ |
+
33 | ++ |
+ #'@importFrom dplyr filter+ |
+
34 | ++ |
+ #'@importFrom dplyr full_join+ |
+
35 | ++ |
+ #'@importFrom dplyr group_split+ |
+
36 | ++ |
+ #'@importFrom dplyr mutate+ |
+
37 | ++ |
+ #'@importFrom dplyr select+ |
+
38 | ++ |
+ #'@importFrom tidyr gather+ |
+
39 | ++ |
+ #'@importFrom magrittr "%>%"+ |
+
40 | ++ |
+ #'@importFrom ggplot2 aes_string+ |
+
41 | ++ |
+ #'@importFrom ggplot2 geom_line+ |
+
42 | ++ |
+ #'@importFrom ggplot2 geom_point+ |
+
43 | ++ |
+ #'@importFrom ggplot2 scale_x_log10+ |
+
44 | ++ |
+ #'@importFrom ggplot2 scale_y_log10+ |
+
45 | ++ |
+ #'@importFrom ggplot2 theme_bw+ |
+
46 | ++ |
+ #'@importFrom ggplot2 ylim+ |
+
47 | ++ |
+ #'@importFrom MASS fitdistr+ |
+
48 | ++ |
+ #'@importFrom purrr map+ |
+
49 | ++ |
+ #'@importFrom purrr reduce+ |
+
50 | ++ |
+ #'@importFrom stats ks.test+ |
+
51 | ++ |
+ #'@importFrom stats glm+ |
+
52 | ++ |
+ #'@importFrom stats logLik+ |
+
53 | ++ |
+ #'@importFrom stats predict+ |
+
54 | ++ |
+ #' @author Derek Corcoran <derek.corcoran.barrios@gmail.com>+ |
+
55 | ++ |
+ #' @author M.Isidora Avila Thieme <msavila@uc.cl>+ |
+
56 | ++ |
+ #' @export+ |
+
57 | ++ | + + | +
58 | ++ | + + | +
59 | ++ |
+ DegreeDistribution <- function(Network, scale = "arithmetic"){+ |
+
60 | +1x | +
+ AIC <- Cumulative <- Exp <- fit <- model <- LogPower <- logLik <- BIC <- Power <- Normal.Resid <- LogExp <- family <- AICcNorm <- NULL+ |
+
61 | +1x | +
+ Network <- .DataInit(Network)+ |
+
62 | +1x | +
+ totaldegree<- degree(Network)+ |
+
63 | +1x | +
+ K <- 0:max(totaldegree)+ |
+
64 | +1x | +
+ For.Graph<- data.frame(K = K, Cumulative = NA)+ |
+
65 | +1x | +
+ for(i in 1:length(K)){+ |
+
66 | +68x | +
+ For.Graph$Cumulative[i] <- sum(totaldegree>K[i])/length(totaldegree)+ |
+
67 | ++ |
+ }+ |
+
68 | +1x | +
+ For.Graph <- For.Graph %>% mutate(LogK = log(K), LogCum = log(Cumulative))+ |
+
69 | ++ | + + | +
70 | ++ | + + | +
71 | ++ |
+ #exponential model nls+ |
+
72 | +1x | +
+ exp.model <- nls(Cumulative~exp(K*lambda+ c),start= list(lambda=0.1, c = 0), data = For.Graph)+ |
+
73 | +1x | +
+ For.Graph$Exp <- predict(exp.model)+ |
+
74 | +1x | +
+ Summs.exp <- glance(exp.model)+ |
+
75 | +1x | +
+ Summs.exp$model <- "Exp"+ |
+
76 | +1x | +
+ Summs.exp$Normal.Resid <- ifelse(tidy(ks.test(augment(exp.model)$.resid,y='pnorm',alternative='two.sided'))$p.value < 0.05, "No", "Yes")+ |
+
77 | +1x | +
+ Summs.exp$family <- "Exponential"+ |
+
78 | +1x | +
+ Summs.exp$AICcNorm <- logLik(MASS::fitdistr(augment(exp.model)$.resid, "normal"))[1]+ |
+
79 | +1x | +
+ Summs.exp$AICcNorm <- (4 - 2*Summs.exp$AICcNorm) + (12/(nrow(augment(exp.model)) - 1))+ |
+
80 | +1x | +
+ Params.exp <- tidy(exp.model)+ |
+
81 | +1x | +
+ Params.exp$model <- "Exp"+ |
+
82 | ++ |
+ #exponential model Log+ |
+
83 | ++ | + + | +
84 | +1x | +
+ power <- filter(For.Graph, K != 0 & Cumulative != 0)+ |
+
85 | +1x | +
+ logexp.model <- glm(LogCum ~ K, data = power)+ |
+
86 | +1x | +
+ power$LogExp <- exp(predict(logexp.model))+ |
+
87 | +1x | +
+ Summs.logexp <- glance(logexp.model)+ |
+
88 | +1x | +
+ Summs.logexp$model <- "LogExp"+ |
+
89 | +1x | +
+ Summs.logexp$Normal.Resid <- ifelse(tidy(ks.test(augment(logexp.model)$.resid,y='pnorm',alternative='two.sided'))$p.value < 0.05, "No", "Yes")+ |
+
90 | +1x | +
+ Summs.logexp$family <- "Exponential"+ |
+
91 | +1x | +
+ Summs.logexp$AICcNorm <- logLik(MASS::fitdistr(augment(logexp.model)$.resid, "normal"))[1]+ |
+
92 | +1x | +
+ Summs.logexp$AICcNorm <- (4 - 2*Summs.logexp$AICcNorm) + (12/(nrow(augment(logexp.model)) - 1))+ |
+
93 | +1x | +
+ Params.logexp <- tidy(logexp.model)+ |
+
94 | +1x | +
+ Params.logexp$model <- "LogExp"+ |
+
95 | ++ | + + | +
96 | ++ |
+ #logpowerlaw+ |
+
97 | ++ | + + | +
98 | +1x | +
+ logpower.model <- glm(LogCum ~ I(log(K)), data = power)+ |
+
99 | +1x | +
+ power$LogPower <- exp(predict(logpower.model))+ |
+
100 | +1x | +
+ For.Graph <- full_join(For.Graph, power)+ |
+
101 | +1x | +
+ Summs.logpower <- glance(logpower.model)+ |
+
102 | +1x | +
+ Summs.logpower$model <- "LogPower"+ |
+
103 | +1x | +
+ Summs.logpower$Normal.Resid <- ifelse(tidy(ks.test(augment(logpower.model)$.resid,y='pnorm',alternative='two.sided'))$p.value < 0.05, "No", "Yes")+ |
+
104 | +1x | +
+ Summs.logpower$family <- "PowerLaw"+ |
+
105 | +1x | +
+ Summs.logpower$AICcNorm <- logLik(MASS::fitdistr(augment(logpower.model)$.resid, "normal"))[1]+ |
+
106 | +1x | +
+ Summs.logpower$AICcNorm <- (4 - 2*Summs.logpower$AICcNorm) + (12/(nrow(augment(logpower.model)) - 1))+ |
+
107 | +1x | +
+ Params.logpower <- tidy(logpower.model)+ |
+
108 | +1x | +
+ Params.logpower$model <- "LogPower"+ |
+
109 | ++ | + + | +
110 | ++ |
+ #powerlaw+ |
+
111 | ++ | + + | +
112 | +1x | +
+ powerlaw.model <- nls(Cumulative~a*K^y, start= list(y=0, a = 1), data = power)+ |
+
113 | +1x | +
+ power$Power <- predict(powerlaw.model)+ |
+
114 | +1x | +
+ For.Graph <- full_join(For.Graph, power)+ |
+
115 | +1x | +
+ Summs.power <- glance(powerlaw.model)+ |
+
116 | +1x | +
+ Summs.power$model <- "Power"+ |
+
117 | +1x | +
+ Summs.power$Normal.Resid <- ifelse(tidy(ks.test(augment(powerlaw.model)$.resid,y='pnorm',alternative='two.sided'))$p.value < 0.05, "No", "Yes")+ |
+
118 | +1x | +
+ Summs.power$family <- "PowerLaw"+ |
+
119 | +1x | +
+ Summs.power$AICcNorm <- logLik(MASS::fitdistr(augment(powerlaw.model)$.resid, "normal"))[1]+ |
+
120 | +1x | +
+ Summs.power$AICcNorm <- (4 - 2*Summs.power$AICcNorm) + (12/(nrow(augment(powerlaw.model)) - 1))+ |
+
121 | +1x | +
+ Params.power <- tidy(powerlaw.model)+ |
+
122 | +1x | +
+ Params.power$model <- "Power"+ |
+
123 | ++ | + + | +
124 | ++ |
+ #all together+ |
+
125 | +1x | +
+ Summs <- full_join(Summs.exp, Summs.power)+ |
+
126 | +1x | +
+ Summs <- full_join(Summs, Summs.logexp)+ |
+
127 | +1x | +
+ Summs <- full_join(Summs, Summs.logpower) %>% select(logLik, AIC, BIC, model, Normal.Resid, family, AICcNorm)+ |
+
128 | +1x | +
+ Summs <- arrange(Summs, Normal.Resid, AIC) %>% dplyr::select(logLik, AIC, BIC, model, Normal.Resid, family)+ |
+
129 | +1x | +
+ params <- bind_rows(Params.logpower, Params.power, Params.logexp, Params.exp) %>%+ |
+
130 | +1x | +
+ dplyr::filter(model %in% Summs$model) %>%+ |
+
131 | +1x | +
+ mutate(term = case_when(term == "y" ~ "Beta",+ |
+
132 | +1x | +
+ term == "a" ~ "c",+ |
+
133 | +1x | +
+ term == "(Intercept)" ~ "c",+ |
+
134 | +1x | +
+ term == "I(log(K))" ~ "Beta",+ |
+
135 | +1x | +
+ term == "lambda" ~ "Lambda",+ |
+
136 | +1x | +
+ term == "K" ~ "Lambda",+ |
+
137 | +1x | +
+ TRUE ~ term))+ |
+
138 | +1x | +
+ DF2 <- For.Graph %>% filter(K != 0 & Cumulative != 0) %>% gather(key = model, value = fit, Exp, Power, LogExp, LogPower) %>% dplyr::filter(model %in% Summs$model)+ |
+
139 | ++ | + + | +
140 | +1x | +
+ g <- ggplot(DF2, aes_string(x = "K", y = "Cumulative")) + geom_line() + geom_point()+ theme_bw() + geom_line(aes_string(y ="fit", color = "model")) + ylim(c(0,1))+ |
+
141 | ++ | + + | +
142 | +1x | +
+ if(scale == "LogLog"){+ |
+
143 | +! | +
+ g <- g + scale_x_log10() + scale_y_log10(breaks=c(0, .001,.01,1))+ |
+
144 | ++ |
+ }+ |
+
145 | ++ | + + | +
146 | +1x | +
+ g+ |
+
147 | ++ | + + | +
148 | +1x | +
+ return(list(DDvalues = For.Graph, models = Summs, graph = g, params = params))+ |
+
149 | ++ |
+ }+ |
+
150 | ++ | + + | +
151 | ++ | + + | +
1 | ++ | + + | +
2 | ++ |
+ #' @param x a network representation as a an adyacency matrix, edgelist,+ |
+
3 | ++ |
+ #' or a network object+ |
+
4 | ++ |
+ #' @importFrom network as.network+ |
+
5 | ++ |
+ #' @importFrom methods is+ |
+
6 | ++ |
+ #' @noRd+ |
+
7 | ++ | + + | +
8 | ++ |
+ .DataInit <- function(x){+ |
+
9 | +140x | +
+ if(is(x) == "network"){+ |
+
10 | +140x | +
+ x+ |
+
11 | ++ |
+ }+ |
+
12 | +140x | +
+ if(is(x) == "matrix"){+ |
+
13 | +! | +
+ x <- as.network(x, loops = TRUE)+ |
+
14 | ++ |
+ }+ |
+
15 | +140x | +
+ return(x)+ |
+
16 | ++ |
+ }+ |
+
1 | ++ |
+ #' Plots the extinctions history of a network+ |
+
2 | ++ |
+ #'+ |
+
3 | ++ |
+ #' It takes a NetworkTopology class object and plots the network index+ |
+
4 | ++ |
+ #' after every extinction+ |
+
5 | ++ |
+ #'+ |
+
6 | ++ |
+ #' @param History a NetworkTopology object obtained from the Mostconnected function+ |
+
7 | ++ |
+ #' or the ExtinctionOrder function+ |
+
8 | ++ |
+ #' @param Variable the variable of the NetworkTopology object that you want as a y variable+ |
+
9 | ++ |
+ #' @return A plot of number of extinctions in the x axis vs the choosen variable in the Y axis+ |
+
10 | ++ |
+ #' @examples+ |
+
11 | ++ |
+ #' # If you don't specify the y variable it will plot the secondary extinctions+ |
+
12 | ++ |
+ #' # by default+ |
+
13 | ++ |
+ #' data("net")+ |
+
14 | ++ |
+ #' history <- SimulateExtinctions(Network = net, Method = "Mostconnected")+ |
+
15 | ++ |
+ #' ExtinctionPlot(History = history$sims)+ |
+
16 | ++ |
+ #' # You can also specify the variable to be ploted in the y axis+ |
+
17 | ++ |
+ #' ExtinctionPlot(History = history$sims, Variable = "Link_density")+ |
+
18 | ++ |
+ #' @importFrom ggplot2 aes_string+ |
+
19 | ++ |
+ #' @importFrom ggplot2 geom_line+ |
+
20 | ++ |
+ #' @importFrom ggplot2 ggplot+ |
+
21 | ++ |
+ #' @importFrom ggplot2 theme_bw+ |
+
22 | ++ |
+ #' @author Derek Corcoran <derek.corcoran.barrios@gmail.com>+ |
+
23 | ++ |
+ #' @author M. Isidora Ávila-Thieme <msavila@uc.cl>+ |
+
24 | ++ |
+ #' @seealso [NetworkExtintion::ExtinctionOrder()]+ |
+
25 | ++ |
+ #' @export+ |
+
26 | ++ | + + | +
27 | ++ |
+ ExtinctionPlot <- function(History, Variable = "AccSecExt"){+ |
+
28 | +1x | +
+ History$X <- 1:nrow(History)+ |
+
29 | +1x | +
+ ggplot(History, aes_string(x = "X", y = Variable)) + geom_line() + theme_bw() + ylab(Variable) + xlab("Primary extinctions")+ |
+
30 | ++ |
+ }+ |
+
").css({position:"fixed",top:0,left:-1*l(y).scrollLeft(),height:1, +width:1,overflow:"hidden"}).append(l("").css({position:"absolute",top:1,left:1,width:100,overflow:"scroll"}).append(l("").css({width:"100%",height:10}))).appendTo("body"),d=c.children(),e=d.children();b.barWidth=d[0].offsetWidth-d[0].clientWidth;b.bScrollOversize=100===e[0].offsetWidth&&100!==d[0].clientWidth;b.bScrollbarLeft=1!==Math.round(e.offset().left);b.bBounding=c[0].getBoundingClientRect().width?!0:!1;c.remove()}l.extend(a.oBrowser,u.__browser);a.oScroll.iBarWidth=u.__browser.barWidth} +function Gb(a,b,c,d,e,h){var f=!1;if(c!==q){var g=c;f=!0}for(;d!==e;)a.hasOwnProperty(d)&&(g=f?b(g,a[d],d,a):a[d],f=!0,d+=h);return g}function cb(a,b){var c=u.defaults.column,d=a.aoColumns.length;c=l.extend({},u.models.oColumn,c,{nTh:b?b:A.createElement("th"),sTitle:c.sTitle?c.sTitle:b?b.innerHTML:"",aDataSort:c.aDataSort?c.aDataSort:[d],mData:c.mData?c.mData:d,idx:d});a.aoColumns.push(c);c=a.aoPreSearchCols;c[d]=l.extend({},u.models.oSearch,c[d]);Ia(a,d,l(b).data())}function Ia(a,b,c){b=a.aoColumns[b]; +var d=a.oClasses,e=l(b.nTh);if(!b.sWidthOrig){b.sWidthOrig=e.attr("width")||null;var h=(e.attr("style")||"").match(/width:\s*(\d+[pxem%]+)/);h&&(b.sWidthOrig=h[1])}c!==q&&null!==c&&(Eb(c),P(u.defaults.column,c,!0),c.mDataProp===q||c.mData||(c.mData=c.mDataProp),c.sType&&(b._sManualType=c.sType),c.className&&!c.sClass&&(c.sClass=c.className),c.sClass&&e.addClass(c.sClass),h=b.sClass,l.extend(b,c),Y(b,c,"sWidth","sWidthOrig"),h!==b.sClass&&(b.sClass=h+" "+b.sClass),c.iDataSort!==q&&(b.aDataSort=[c.iDataSort]), +Y(b,c,"aDataSort"));var f=b.mData,g=ma(f),k=b.mRender?ma(b.mRender):null;c=function(m){return"string"===typeof m&&-1!==m.indexOf("@")};b._bAttrSrc=l.isPlainObject(f)&&(c(f.sort)||c(f.type)||c(f.filter));b._setter=null;b.fnGetData=function(m,n,p){var t=g(m,n,q,p);return k&&n?k(t,n,m,p):t};b.fnSetData=function(m,n,p){return ha(f)(m,n,p)};"number"!==typeof f&&(a._rowReadObject=!0);a.oFeatures.bSort||(b.bSortable=!1,e.addClass(d.sSortableNone));a=-1!==l.inArray("asc",b.asSorting);c=-1!==l.inArray("desc", +b.asSorting);b.bSortable&&(a||c)?a&&!c?(b.sSortingClass=d.sSortableAsc,b.sSortingClassJUI=d.sSortJUIAscAllowed):!a&&c?(b.sSortingClass=d.sSortableDesc,b.sSortingClassJUI=d.sSortJUIDescAllowed):(b.sSortingClass=d.sSortable,b.sSortingClassJUI=d.sSortJUI):(b.sSortingClass=d.sSortableNone,b.sSortingClassJUI="")}function sa(a){if(!1!==a.oFeatures.bAutoWidth){var b=a.aoColumns;db(a);for(var c=0,d=b.length;cm[n])d(g.length+m[n],k);else if("string"===typeof m[n]){var p=0;for(f=g.length;p b&&a[e]--; -1!=d&&c===q&&a.splice(d,1)}function va(a,b,c,d){var e=a.aoData[b],h,f=function(k,m){for(;k.childNodes.length;)k.removeChild(k.firstChild);k.innerHTML=T(a,b,m,"display")};if("dom"!==c&&(c&&"auto"!==c||"dom"!==e.src)){var g=e.anCells;if(g)if(d!==q)f(g[d],d);else for(c=0,h=g.length;c ").appendTo(d));var k=0;for(b=g.length;k=a.fnRecordsDisplay()?0:d,a.iInitDisplayStart=-1);c=F(a,"aoPreDrawCallback","preDraw",[a]);if(-1!==l.inArray(!1,c))V(a,!1);else{c=[];var e=0;d=a.asStripeClasses;var h=d.length,f=a.oLanguage,g="ssp"==Q(a),k=a.aiDisplay,m=a._iDisplayStart,n=a.fnDisplayEnd();a.bDrawing=!0;if(a.bDeferLoading)a.bDeferLoading=!1,a.iDraw++,V(a,!1);else if(!g)a.iDraw++;else if(!a.bDestroying&&!b){Kb(a);return}if(0!==k.length)for(b=g?a.aoData.length:n,f=g?0:m;f",{"class":h?d[0]:""}).append(l(" ",{valign:"top",colSpan:na(a),"class":a.oClasses.sRowEmpty}).html(e))[0];F(a,"aoHeaderCallback","header",[l(a.nTHead).children("tr")[0], +ib(a),m,n,k]);F(a,"aoFooterCallback","footer",[l(a.nTFoot).children("tr")[0],ib(a),m,n,k]);d=l(a.nTBody);d.children().detach();d.append(l(c));F(a,"aoDrawCallback","draw",[a]);a.bSorted=!1;a.bFiltered=!1;a.bDrawing=!1}}function ka(a,b){var c=a.oFeatures,d=c.bFilter;c.bSort&&Lb(a);d?ya(a,a.oPreviousSearch):a.aiDisplay=a.aiDisplayMaster.slice();!0!==b&&(a._iDisplayStart=0);a._drawHold=b;ja(a);a._drawHold=!1}function Mb(a){var b=a.oClasses,c=l(a.nTable);c=l("").insertBefore(c);var d=a.oFeatures, +e=l("",{id:a.sTableId+"_wrapper","class":b.sWrapper+(a.nTFoot?"":" "+b.sNoFooter)});a.nHolding=c[0];a.nTableWrapper=e[0];a.nTableReinsertBefore=a.nTable.nextSibling;for(var h=a.sDom.split(""),f,g,k,m,n,p,t=0;t ")[0];m=h[t+1];if("'"==m||'"'==m){n="";for(p=2;h[t+p]!=m;)n+=h[t+p],p++;"H"==n?n=b.sJUIHeader:"F"==n&&(n=b.sJUIFooter);-1!=n.indexOf(".")?(m=n.split("."),k.id=m[0].substr(1,m[0].length-1),k.className=m[1]):"#"==n.charAt(0)?k.id=n.substr(1, +n.length-1):k.className=n;t+=p}e.append(k);e=l(k)}else if(">"==g)e=e.parent();else if("l"==g&&d.bPaginate&&d.bLengthChange)f=Nb(a);else if("f"==g&&d.bFilter)f=Ob(a);else if("r"==g&&d.bProcessing)f=Pb(a);else if("t"==g)f=Qb(a);else if("i"==g&&d.bInfo)f=Rb(a);else if("p"==g&&d.bPaginate)f=Sb(a);else if(0!==u.ext.feature.length)for(k=u.ext.feature,p=0,m=k.length;p ',g=d.sSearch;g=g.match(/_INPUT_/)?g.replace("_INPUT_",f):g+f;b=l("",{id:h.f?null:c+"_filter","class":b.sFilter}).append(l("").append(g));var k=function(n){var p=this.value?this.value:"";e.return&&"Enter"!==n.key||p==e.sSearch||(ya(a,{sSearch:p,bRegex:e.bRegex,bSmart:e.bSmart,bCaseInsensitive:e.bCaseInsensitive,"return":e.return}), +a._iDisplayStart=0,ja(a))};h=null!==a.searchDelay?a.searchDelay:"ssp"===Q(a)?400:0;var m=l("input",b).val(e.sSearch).attr("placeholder",d.sSearchPlaceholder).on("keyup.DT search.DT input.DT paste.DT cut.DT",h?mb(k,h):k).on("mouseup",function(n){setTimeout(function(){k.call(m[0],n)},10)}).on("keypress.DT",function(n){if(13==n.keyCode)return!1}).attr("aria-controls",c);l(a.nTable).on("search.dt.DT",function(n,p){if(a===p)try{m[0]!==A.activeElement&&m.val(e.sSearch)}catch(t){}});return b[0]}function ya(a, +b,c){var d=a.oPreviousSearch,e=a.aoPreSearchCols,h=function(g){d.sSearch=g.sSearch;d.bRegex=g.bRegex;d.bSmart=g.bSmart;d.bCaseInsensitive=g.bCaseInsensitive;d.return=g.return},f=function(g){return g.bEscapeRegex!==q?!g.bEscapeRegex:g.bRegex};eb(a);if("ssp"!=Q(a)){Vb(a,b.sSearch,c,f(b),b.bSmart,b.bCaseInsensitive,b.return);h(b);for(b=0;b =b.length)a.aiDisplay= +g.slice();else{if(k||c||d||f.length>b.length||0!==b.indexOf(f)||a.bSorted)a.aiDisplay=g.slice();b=a.aiDisplay;for(c=0;c ",{"class":a.oClasses.sInfo,id:c?null:b+"_info"});c||(a.aoDrawCallback.push({fn:ac,sName:"information"}),d.attr("role","status").attr("aria-live","polite"),l(a.nTable).attr("aria-describedby",b+"_info"));return d[0]}function ac(a){var b=a.aanFeatures.i;if(0!==b.length){var c=a.oLanguage,d=a._iDisplayStart+1,e=a.fnDisplayEnd(),h=a.fnRecordsTotal(), +f=a.fnRecordsDisplay(),g=f?c.sInfo:c.sInfoEmpty;f!==h&&(g+=" "+c.sInfoFiltered);g+=c.sInfoPostFix;g=bc(a,g);c=c.fnInfoCallback;null!==c&&(g=c.call(a.oInstance,a,d,e,h,f,g));l(b).html(g)}}function bc(a,b){var c=a.fnFormatNumber,d=a._iDisplayStart+1,e=a._iDisplayLength,h=a.fnRecordsDisplay(),f=-1===e;return b.replace(/_START_/g,c.call(a,d)).replace(/_END_/g,c.call(a,a.fnDisplayEnd())).replace(/_MAX_/g,c.call(a,a.fnRecordsTotal())).replace(/_TOTAL_/g,c.call(a,h)).replace(/_PAGE_/g,c.call(a,f?1:Math.ceil(d/ +e))).replace(/_PAGES_/g,c.call(a,f?1:Math.ceil(h/e)))}function Aa(a){var b=a.iInitDisplayStart,c=a.aoColumns;var d=a.oFeatures;var e=a.bDeferLoading;if(a.bInitialised){Mb(a);Jb(a);xa(a,a.aoHeader);xa(a,a.aoFooter);V(a,!0);d.bAutoWidth&&db(a);var h=0;for(d=c.length;h ",{name:c+"_length","aria-controls":c,"class":b.sLengthSelect});for(var f=0,g=h.length;f ").addClass(b.sLength);a.aanFeatures.l||(k[0].id=c+"_length");k.children().append(a.oLanguage.sLengthMenu.replace("_MENU_",e[0].outerHTML));l("select",k).val(a._iDisplayLength).on("change.DT",function(m){pb(a,l(this).val());ja(a)});l(a.nTable).on("length.dt.DT",function(m,n,p){a===n&&l("select",k).val(p)});return k[0]}function Sb(a){var b=a.sPaginationType,c=u.ext.pager[b],d="function"===typeof c,e=function(f){ja(f)};b=l("").addClass(a.oClasses.sPaging+ +b)[0];var h=a.aanFeatures;d||c.fnInit(a,b,e);h.p||(b.id=a.sTableId+"_paginate",a.aoDrawCallback.push({fn:function(f){if(d){var g=f._iDisplayStart,k=f._iDisplayLength,m=f.fnRecordsDisplay(),n=-1===k;g=n?0:Math.ceil(g/k);k=n?1:Math.ceil(m/k);m=c(g,k);var p;n=0;for(p=h.p.length;n h&&(d=0)):"first"==b?d=0:"previous"==b?(d=0<=e?d-e:0,0>d&&(d=0)):"next"==b?d+e
",{id:a.aanFeatures.r?null:a.sTableId+"_processing","class":a.oClasses.sProcessing}).html(a.oLanguage.sProcessing).append(" ").insertBefore(a.nTable)[0]}function V(a, +b){a.oFeatures.bProcessing&&l(a.aanFeatures.r).css("display",b?"block":"none");F(a,null,"processing",[a,b])}function Qb(a){var b=l(a.nTable),c=a.oScroll;if(""===c.sX&&""===c.sY)return a.nTable;var d=c.sX,e=c.sY,h=a.oClasses,f=b.children("caption"),g=f.length?f[0]._captionSide:null,k=l(b[0].cloneNode(!1)),m=l(b[0].cloneNode(!1)),n=b.children("tfoot");n.length||(n=null);k=l("",{"class":h.sScrollWrapper}).append(l("",{"class":h.sScrollHead}).css({overflow:"hidden",position:"relative",border:0, +width:d?d?K(d):null:"100%"}).append(l("",{"class":h.sScrollHeadInner}).css({"box-sizing":"content-box",width:c.sXInner||"100%"}).append(k.removeAttr("id").css("margin-left",0).append("top"===g?f:null).append(b.children("thead"))))).append(l("",{"class":h.sScrollBody}).css({position:"relative",overflow:"auto",width:d?K(d):null}).append(b));n&&k.append(l("",{"class":h.sScrollFoot}).css({overflow:"hidden",border:0,width:d?d?K(d):null:"100%"}).append(l("",{"class":h.sScrollFootInner}).append(m.removeAttr("id").css("margin-left", +0).append("bottom"===g?f:null).append(b.children("tfoot")))));b=k.children();var p=b[0];h=b[1];var t=n?b[2]:null;if(d)l(h).on("scroll.DT",function(v){v=this.scrollLeft;p.scrollLeft=v;n&&(t.scrollLeft=v)});l(h).css("max-height",e);c.bCollapse||l(h).css("height",e);a.nScrollHead=p;a.nScrollBody=h;a.nScrollFoot=t;a.aoDrawCallback.push({fn:Ja,sName:"scrolling"});return k[0]}function Ja(a){var b=a.oScroll,c=b.sX,d=b.sXInner,e=b.sY;b=b.iBarWidth;var h=l(a.nScrollHead),f=h[0].style,g=h.children("div"),k= +g[0].style,m=g.children("table");g=a.nScrollBody;var n=l(g),p=g.style,t=l(a.nScrollFoot).children("div"),v=t.children("table"),x=l(a.nTHead),w=l(a.nTable),r=w[0],C=r.style,G=a.nTFoot?l(a.nTFoot):null,ba=a.oBrowser,L=ba.bScrollOversize;U(a.aoColumns,"nTh");var O=[],I=[],H=[],fa=[],Z,Ba=function(D){D=D.style;D.paddingTop="0";D.paddingBottom="0";D.borderTopWidth="0";D.borderBottomWidth="0";D.height=0};var X=g.scrollHeight>g.clientHeight;if(a.scrollBarVis!==X&&a.scrollBarVis!==q)a.scrollBarVis=X,sa(a); +else{a.scrollBarVis=X;w.children("thead, tfoot").remove();if(G){X=G.clone().prependTo(w);var ca=G.find("tr");var Ca=X.find("tr");X.find("[id]").removeAttr("id")}var Ua=x.clone().prependTo(w);x=x.find("tr");X=Ua.find("tr");Ua.find("th, td").removeAttr("tabindex");Ua.find("[id]").removeAttr("id");c||(p.width="100%",h[0].style.width="100%");l.each(Pa(a,Ua),function(D,W){Z=ta(a,D);W.style.width=a.aoColumns[Z].sWidth});G&&da(function(D){D.style.width=""},Ca);h=w.outerWidth();""===c?(C.width="100%",L&& +(w.find("tbody").height()>g.offsetHeight||"scroll"==n.css("overflow-y"))&&(C.width=K(w.outerWidth()-b)),h=w.outerWidth()):""!==d&&(C.width=K(d),h=w.outerWidth());da(Ba,X);da(function(D){var W=y.getComputedStyle?y.getComputedStyle(D).width:K(l(D).width());H.push(D.innerHTML);O.push(W)},X);da(function(D,W){D.style.width=O[W]},x);l(X).css("height",0);G&&(da(Ba,Ca),da(function(D){fa.push(D.innerHTML);I.push(K(l(D).css("width")))},Ca),da(function(D,W){D.style.width=I[W]},ca),l(Ca).height(0));da(function(D, +W){D.innerHTML=''+H[W]+"";D.childNodes[0].style.height="0";D.childNodes[0].style.overflow="hidden";D.style.width=O[W]},X);G&&da(function(D,W){D.innerHTML=''+fa[W]+"";D.childNodes[0].style.height="0";D.childNodes[0].style.overflow="hidden";D.style.width=I[W]},Ca);Math.round(w.outerWidth())g.offsetHeight||"scroll"==n.css("overflow-y")?h+b:h,L&&(g.scrollHeight>g.offsetHeight||"scroll"==n.css("overflow-y"))&& +(C.width=K(ca-b)),""!==c&&""===d||ea(a,1,"Possible column misalignment",6)):ca="100%";p.width=K(ca);f.width=K(ca);G&&(a.nScrollFoot.style.width=K(ca));!e&&L&&(p.height=K(r.offsetHeight+b));c=w.outerWidth();m[0].style.width=K(c);k.width=K(c);d=w.height()>g.clientHeight||"scroll"==n.css("overflow-y");e="padding"+(ba.bScrollbarLeft?"Left":"Right");k[e]=d?b+"px":"0px";G&&(v[0].style.width=K(c),t[0].style.width=K(c),t[0].style[e]=d?b+"px":"0px");w.children("colgroup").insertBefore(w.children("thead")); +n.trigger("scroll");!a.bSorted&&!a.bFiltered||a._drawHold||(g.scrollTop=0)}}function da(a,b,c){for(var d=0,e=0,h=b.length,f,g;e ").appendTo(g.find("tbody"));g.find("thead, tfoot").remove();g.append(l(a.nTHead).clone()).append(l(a.nTFoot).clone());g.find("tfoot th, tfoot td").css("width","");m=Pa(a,g.find("thead")[0]); +for(v=0;v ").css({width:w.sWidthOrig,margin:0,padding:0,border:0,height:1}));if(a.aoData.length)for(v=0;v ").css(h||e?{position:"absolute",top:0,left:0,height:1,right:0,overflow:"hidden"}:{}).append(g).appendTo(p);h&&f?g.width(f):h? +(g.css("width","auto"),g.removeAttr("width"),g.width() ").css("width",K(a)).appendTo(b||A.body);b=a[0].offsetWidth;a.remove();return b}function dc(a,b){var c=ec(a,b);if(0>c)return null;var d=a.aoData[c];return d.nTr?d.anCells[b]:l(" ").html(T(a,c,b,"display"))[0]}function ec(a,b){for(var c,d=-1,e=-1,h=0,f=a.aoData.length;h d&&(d=c.length,e=h);return e}function K(a){return null===a?"0px":"number"==typeof a?0>a?"0px":a+"px":a.match(/\d$/)?a+"px":a}function oa(a){var b= +[],c=a.aoColumns;var d=a.aaSortingFixed;var e=l.isPlainObject(d);var h=[];var f=function(n){n.length&&!Array.isArray(n[0])?h.push(n):l.merge(h,n)};Array.isArray(d)&&f(d);e&&d.pre&&f(d.pre);f(a.aaSorting);e&&d.post&&f(d.post);for(a=0;a G?1:0;if(0!==C)return"asc"===r.dir?C:-C}C=c[n];G=c[p];return C G?1:0}):f.sort(function(n,p){var t,v=g.length, +x=e[n]._aSortData,w=e[p]._aSortData;for(t=0;t G?1:0})}a.bSorted=!0}function gc(a){var b=a.aoColumns,c=oa(a);a=a.oLanguage.oAria;for(var d=0,e=b.length;d /g,"");var k=h.nTh;k.removeAttribute("aria-sort");h.bSortable&&(0 e?e+1:3))}e=0;for(h=d.length;e e?e+1:3))}a.aLastSort=d}function fc(a,b){var c=a.aoColumns[b],d=u.ext.order[c.sSortDataType],e;d&&(e=d.call(a.oInstance,a,b,ua(a,b)));for(var h,f=u.ext.type.order[c.sType+"-pre"],g=0,k=a.aoData.length;g =e.length?[0,m[1]]:m)}));b.search!==q&&l.extend(a.oPreviousSearch,$b(b.search));if(b.columns){f=0;for(d=b.columns.length;f =c&&(b=c-d);b-=b%d;if(-1===d||0>b)b=0;a._iDisplayStart=b}function lb(a,b){a=a.renderer;var c=u.ext.renderer[b]; +return l.isPlainObject(a)&&a[b]?c[a[b]]||c._:"string"===typeof a?c[a]||c._:c._}function Q(a){return a.oFeatures.bServerSide?"ssp":a.ajax||a.sAjaxSource?"ajax":"dom"}function Ea(a,b){var c=ic.numbers_length,d=Math.floor(c/2);b<=c?a=pa(0,b):a<=d?(a=pa(0,c-2),a.push("ellipsis"),a.push(b-1)):(a>=b-1-d?a=pa(b-(c-2),b):(a=pa(a-d+2,a+d-1),a.push("ellipsis"),a.push(b-1)),a.splice(0,0,"ellipsis"),a.splice(0,0,0));a.DT_el="span";return a}function bb(a){l.each({num:function(b){return Xa(b,a)},"num-fmt":function(b){return Xa(b, +a,vb)},"html-num":function(b){return Xa(b,a,Ya)},"html-num-fmt":function(b){return Xa(b,a,Ya,vb)}},function(b,c){M.type.order[b+a+"-pre"]=c;b.match(/^html\-/)&&(M.type.search[b+a]=M.type.search.html)})}function jc(a,b,c,d,e){return y.moment?a[b](e):y.luxon?a[c](e):d?a[d](e):a}function Za(a,b,c){if(y.moment){var d=y.moment.utc(a,b,c,!0);if(!d.isValid())return null}else if(y.luxon){d=b?y.luxon.DateTime.fromFormat(a,b):y.luxon.DateTime.fromISO(a);if(!d.isValid)return null;d.setLocale(c)}else b?(kc|| +alert("DataTables warning: Formatted date without Moment.js or Luxon - https://datatables.net/tn/17"),kc=!0):d=new Date(a);return d}function wb(a){return function(b,c,d,e){0===arguments.length?(d="en",b=c=null):1===arguments.length?(d="en",c=b,b=null):2===arguments.length&&(d=c,c=b,b=null);var h="datetime-"+c;u.ext.type.order[h]||(u.ext.type.detect.unshift(function(f){return f===h?h:!1}),u.ext.type.order[h+"-asc"]=function(f,g){f=f.valueOf();g=g.valueOf();return f===g?0:f g?-1:1});return function(f,g){if(null===f||f===q)"--now"===e?(f=new Date,f=new Date(Date.UTC(f.getFullYear(),f.getMonth(),f.getDate(),f.getHours(),f.getMinutes(),f.getSeconds()))):f="";if("type"===g)return h;if(""===f)return"sort"!==g?"":Za("0000-01-01 00:00:00",null,d);if(null!==c&&b===c&&"sort"!==g&&"type"!==g&&!(f instanceof Date))return f;var k=Za(f,b,d);if(null===k)return f;if("sort"===g)return k;f=null===c?jc(k,"toDate","toJSDate", +"")[a]():jc(k,"format","toFormat","toISOString",c);return"display"===g?$a(f):f}}}function lc(a){return function(){var b=[Wa(this[u.ext.iApiIndex])].concat(Array.prototype.slice.call(arguments));return u.ext.internal[a].apply(this,b)}}var u=function(a,b){if(this instanceof u)return l(a).DataTable(b);b=a;this.$=function(f,g){return this.api(!0).$(f,g)};this._=function(f,g){return this.api(!0).rows(f,g).data()};this.api=function(f){return f?new B(Wa(this[M.iApiIndex])):new B(this)};this.fnAddData=function(f, +g){var k=this.api(!0);f=Array.isArray(f)&&(Array.isArray(f[0])||l.isPlainObject(f[0]))?k.rows.add(f):k.row.add(f);(g===q||g)&&k.draw();return f.flatten().toArray()};this.fnAdjustColumnSizing=function(f){var g=this.api(!0).columns.adjust(),k=g.settings()[0],m=k.oScroll;f===q||f?g.draw(!1):(""!==m.sX||""!==m.sY)&&Ja(k)};this.fnClearTable=function(f){var g=this.api(!0).clear();(f===q||f)&&g.draw()};this.fnClose=function(f){this.api(!0).row(f).child.hide()};this.fnDeleteRow=function(f,g,k){var m=this.api(!0); +f=m.rows(f);var n=f.settings()[0],p=n.aoData[f[0][0]];f.remove();g&&g.call(this,n,p);(k===q||k)&&m.draw();return p};this.fnDestroy=function(f){this.api(!0).destroy(f)};this.fnDraw=function(f){this.api(!0).draw(f)};this.fnFilter=function(f,g,k,m,n,p){n=this.api(!0);null===g||g===q?n.search(f,k,m,p):n.column(g).search(f,k,m,p);n.draw()};this.fnGetData=function(f,g){var k=this.api(!0);if(f!==q){var m=f.nodeName?f.nodeName.toLowerCase():"";return g!==q||"td"==m||"th"==m?k.cell(f,g).data():k.row(f).data()|| +null}return k.data().toArray()};this.fnGetNodes=function(f){var g=this.api(!0);return f!==q?g.row(f).node():g.rows().nodes().flatten().toArray()};this.fnGetPosition=function(f){var g=this.api(!0),k=f.nodeName.toUpperCase();return"TR"==k?g.row(f).index():"TD"==k||"TH"==k?(f=g.cell(f).index(),[f.row,f.columnVisible,f.column]):null};this.fnIsOpen=function(f){return this.api(!0).row(f).child.isShown()};this.fnOpen=function(f,g,k){return this.api(!0).row(f).child(g,k).show().child()[0]};this.fnPageChange= +function(f,g){f=this.api(!0).page(f);(g===q||g)&&f.draw(!1)};this.fnSetColumnVis=function(f,g,k){f=this.api(!0).column(f).visible(g);(k===q||k)&&f.columns.adjust().draw()};this.fnSettings=function(){return Wa(this[M.iApiIndex])};this.fnSort=function(f){this.api(!0).order(f).draw()};this.fnSortListener=function(f,g,k){this.api(!0).order.listener(f,g,k)};this.fnUpdate=function(f,g,k,m,n){var p=this.api(!0);k===q||null===k?p.row(g).data(f):p.cell(g,k).data(f);(n===q||n)&&p.columns.adjust();(m===q||m)&& +p.draw();return 0};this.fnVersionCheck=M.fnVersionCheck;var c=this,d=b===q,e=this.length;d&&(b={});this.oApi=this.internal=M.internal;for(var h in u.ext.internal)h&&(this[h]=lc(h));this.each(function(){var f={},g=1 /g,">").replace(/"/g, +"""):a},kc=!1,zc=",",Ac=".";if(Intl)try{for(var Ha=(new Intl.NumberFormat).formatToParts(100000.1),ra=0;ra").appendTo(t));r.nTHead=H[0];var fa=t.children("tbody");0===fa.length&&(fa=l("").insertAfter(H));r.nTBody=fa[0];H=t.children("tfoot");0===H.length&&0 ").appendTo(t));0===H.length||0===H.children().length?t.addClass(C.sNoFooter):0 /g,Dc=/^\d{2,4}[\.\/\-]\d{1,2}[\.\/\-]\d{1,2}([T ]{1}\d{1,2}[:\.]\d{2}([\.:]\d{2})?)?$/,Ec=/(\/|\.|\*|\+|\?|\||\(|\)|\[|\]|\{|\}|\\|\$|\^|\-)/g,vb=/['\u00A0,$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfkɃΞ]/gi,aa=function(a){return a&&!0!==a&&"-"!== +a?!1:!0},nc=function(a){var b=parseInt(a,10);return!isNaN(b)&&isFinite(a)?b:null},oc=function(a,b){xb[b]||(xb[b]=new RegExp(ob(b),"g"));return"string"===typeof a&&"."!==b?a.replace(/\./g,"").replace(xb[b],"."):a},yb=function(a,b,c){var d="string"===typeof a;if(aa(a))return!0;b&&d&&(a=oc(a,b));c&&d&&(a=a.replace(vb,""));return!isNaN(parseFloat(a))&&isFinite(a)},pc=function(a,b,c){return aa(a)?!0:aa(a)||"string"===typeof a?yb(a.replace(Ya,""),b,c)?!0:null:null},U=function(a,b,c){var d=[],e=0,h=a.length; +if(c!==q)for(;e a.length)){var b=a.slice().sort();for(var c=b[0], +d=1,e=b.length;d ")[0],Bc=Sa.textContent!==q,Cc=/<.*?>/g,mb=u.util.throttle,tc=[],N=Array.prototype,Fc=function(a){var b,c=u.settings,d=l.map(c,function(h,f){return h.nTable});if(a){if(a.nTable&&a.oApi)return[a];if(a.nodeName&&"table"===a.nodeName.toLowerCase()){var e= +l.inArray(a,d);return-1!==e?[c[e]]:null}if(a&&"function"===typeof a.settings)return a.settings().toArray();"string"===typeof a?b=l(a):a instanceof l&&(b=a)}else return[];if(b)return b.map(function(h){e=l.inArray(this,d);return-1!==e?c[e]:null}).toArray()};var B=function(a,b){if(!(this instanceof B))return new B(a,b);var c=[],d=function(f){(f=Fc(f))&&c.push.apply(c,f)};if(Array.isArray(a))for(var e=0,h=a.length;e a?new B(b[a],this[a]):null},filter:function(a){var b=[];if(N.filter)b=N.filter.call(this,a,this);else for(var c=0,d=this.length;c ").addClass(g),l("td",k).addClass(g).html(f)[0].colSpan=na(a),e.push(k[0]))};h(c,d);b._details&&b._details.detach();b._details=l(e);b._detailsShow&&b._details.insertAfter(b.nTr)},wc=u.util.throttle(function(a){Da(a[0])}, +500),Cb=function(a,b){var c=a.context;c.length&&(a=c[0].aoData[b!==q?b:a[0]])&&a._details&&(a._details.remove(),a._detailsShow=q,a._details=q,l(a.nTr).removeClass("dt-hasChild"),wc(c))},xc=function(a,b){var c=a.context;if(c.length&&a.length){var d=c[0].aoData[a[0]];d._details&&((d._detailsShow=b)?(d._details.insertAfter(d.nTr),l(d.nTr).addClass("dt-hasChild")):(d._details.detach(),l(d.nTr).removeClass("dt-hasChild")),F(c[0],null,"childRow",[b,a.row(a[0])]),Ic(c[0]),wc(c))}},Ic=function(a){var b=new B(a), +c=a.aoData;b.off("draw.dt.DT_details column-sizing.dt.DT_details destroy.dt.DT_details");0g){var n=l.map(d,function(p,t){return p.bVisible?t:null});return[n[n.length+g]]}return[ta(a,g)];case "name":return l.map(e,function(p,t){return p===m[1]?t:null});default:return[]}if(f.nodeName&&f._DT_CellIndex)return[f._DT_CellIndex.column];g=l(h).filter(f).map(function(){return l.inArray(this,h)}).toArray();if(g.length||!f.nodeName)return g; +g=l(f).closest("*[data-dt-column]");return g.length?[g.data("dt-column")]:[]},a,c)};z("columns()",function(a,b){a===q?a="":l.isPlainObject(a)&&(b=a,a="");b=Ab(b);var c=this.iterator("table",function(d){return Kc(d,a,b)},1);c.selector.cols=a;c.selector.opts=b;return c});J("columns().header()","column().header()",function(a,b){return this.iterator("column",function(c,d){return c.aoColumns[d].nTh},1)});J("columns().footer()","column().footer()",function(a,b){return this.iterator("column",function(c, +d){return c.aoColumns[d].nTf},1)});J("columns().data()","column().data()",function(){return this.iterator("column-rows",yc,1)});J("columns().dataSrc()","column().dataSrc()",function(){return this.iterator("column",function(a,b){return a.aoColumns[b].mData},1)});J("columns().cache()","column().cache()",function(a){return this.iterator("column-rows",function(b,c,d,e,h){return Fa(b.aoData,h,"search"===a?"_aFilterData":"_aSortData",c)},1)});J("columns().nodes()","column().nodes()",function(){return this.iterator("column-rows", +function(a,b,c,d,e){return Fa(a.aoData,e,"anCells",b)},1)});J("columns().visible()","column().visible()",function(a,b){var c=this,d=this.iterator("column",function(e,h){if(a===q)return e.aoColumns[h].bVisible;var f=e.aoColumns,g=f[h],k=e.aoData,m;if(a!==q&&g.bVisible!==a){if(a){var n=l.inArray(!0,U(f,"bVisible"),h+1);f=0;for(m=k.length;f d;return!0};u.isDataTable=u.fnIsDataTable=function(a){var b=l(a).get(0),c=!1;if(a instanceof u.Api)return!0;l.each(u.settings,function(d,e){d=e.nScrollHead?l("table",e.nScrollHead)[0]:null;var h=e.nScrollFoot? +l("table",e.nScrollFoot)[0]:null;if(e.nTable===b||d===b||h===b)c=!0});return c};u.tables=u.fnTables=function(a){var b=!1;l.isPlainObject(a)&&(b=a.api,a=a.visible);var c=l.map(u.settings,function(d){if(!a||a&&l(d.nTable).is(":visible"))return d.nTable});return b?new B(c):c};u.camelToHungarian=P;z("$()",function(a,b){b=this.rows(b).nodes();b=l(b);return l([].concat(b.filter(a).toArray(),b.find(a).toArray()))});l.each(["on","one","off"],function(a,b){z(b+"()",function(){var c=Array.prototype.slice.call(arguments); +c[0]=l.map(c[0].split(/\s/),function(e){return e.match(/\.dt\b/)?e:e+".dt"}).join(" ");var d=l(this.tables().nodes());d[b].apply(d,c);return this})});z("clear()",function(){return this.iterator("table",function(a){Ma(a)})});z("settings()",function(){return new B(this.context,this.context)});z("init()",function(){var a=this.context;return a.length?a[0].oInit:null});z("data()",function(){return this.iterator("table",function(a){return U(a.aoData,"_aData")}).flatten()});z("destroy()",function(a){a=a|| +!1;return this.iterator("table",function(b){var c=b.oClasses,d=b.nTable,e=b.nTBody,h=b.nTHead,f=b.nTFoot,g=l(d);e=l(e);var k=l(b.nTableWrapper),m=l.map(b.aoData,function(p){return p.nTr}),n;b.bDestroying=!0;F(b,"aoDestroyCallback","destroy",[b]);a||(new B(b)).columns().visible(!0);k.off(".DT").find(":not(tbody *)").off(".DT");l(y).off(".DT-"+b.sInstance);d!=h.parentNode&&(g.children("thead").detach(),g.append(h));f&&d!=f.parentNode&&(g.children("tfoot").detach(),g.append(f));b.aaSorting=[];b.aaSortingFixed= +[];Va(b);l(m).removeClass(b.asStripeClasses.join(" "));l("th, td",h).removeClass(c.sSortable+" "+c.sSortableAsc+" "+c.sSortableDesc+" "+c.sSortableNone);e.children().detach();e.append(m);h=b.nTableWrapper.parentNode;f=a?"remove":"detach";g[f]();k[f]();!a&&h&&(h.insertBefore(d,b.nTableReinsertBefore),g.css("width",b.sDestroyWidth).removeClass(c.sTable),(n=b.asDestroyStripes.length)&&e.children().each(function(p){l(this).addClass(b.asDestroyStripes[p%n])}));c=l.inArray(b,u.settings);-1!==c&&u.settings.splice(c, +1)})});l.each(["column","row","cell"],function(a,b){z(b+"s().every()",function(c){var d=this.selector.opts,e=this;return this.iterator(b,function(h,f,g,k,m){c.call(e[b](f,"cell"===b?g:d,"cell"===b?d:q),f,g,k,m)})})});z("i18n()",function(a,b,c){var d=this.context[0];a=ma(a)(d.oLanguage);a===q&&(a=b);c!==q&&l.isPlainObject(a)&&(a=a[c]!==q?a[c]:a._);return a.replace("%d",c)});u.version="1.12.1";u.settings=[];u.models={};u.models.oSearch={bCaseInsensitive:!0,sSearch:"",bRegex:!1,bSmart:!0,"return":!1}; +u.models.oRow={nTr:null,anCells:null,_aData:[],_aSortData:null,_aFilterData:null,_sFilterRow:null,_sRowStripe:"",src:null,idx:-1};u.models.oColumn={idx:null,aDataSort:null,asSorting:null,bSearchable:null,bSortable:null,bVisible:null,_sManualType:null,_bAttrSrc:!1,fnCreatedCell:null,fnGetData:null,fnSetData:null,mData:null,mRender:null,nTh:null,nTf:null,sClass:null,sContentPadding:null,sDefaultContent:null,sName:null,sSortDataType:"std",sSortingClass:null,sSortingClassJUI:null,sTitle:null,sType:null, +sWidth:null,sWidthOrig:null};u.defaults={aaData:null,aaSorting:[[0,"asc"]],aaSortingFixed:[],ajax:null,aLengthMenu:[10,25,50,100],aoColumns:null,aoColumnDefs:null,aoSearchCols:[],asStripeClasses:null,bAutoWidth:!0,bDeferRender:!1,bDestroy:!1,bFilter:!0,bInfo:!0,bLengthChange:!0,bPaginate:!0,bProcessing:!1,bRetrieve:!1,bScrollCollapse:!1,bServerSide:!1,bSort:!0,bSortMulti:!0,bSortCellsTop:!1,bSortClasses:!0,bStateSave:!1,fnCreatedRow:null,fnDrawCallback:null,fnFooterCallback:null,fnFormatNumber:function(a){return a.toString().replace(/\B(?=(\d{3})+(?!\d))/g, +this.oLanguage.sThousands)},fnHeaderCallback:null,fnInfoCallback:null,fnInitComplete:null,fnPreDrawCallback:null,fnRowCallback:null,fnServerData:null,fnServerParams:null,fnStateLoadCallback:function(a){try{return JSON.parse((-1===a.iStateDuration?sessionStorage:localStorage).getItem("DataTables_"+a.sInstance+"_"+location.pathname))}catch(b){return{}}},fnStateLoadParams:null,fnStateLoaded:null,fnStateSaveCallback:function(a,b){try{(-1===a.iStateDuration?sessionStorage:localStorage).setItem("DataTables_"+ +a.sInstance+"_"+location.pathname,JSON.stringify(b))}catch(c){}},fnStateSaveParams:null,iStateDuration:7200,iDeferLoading:null,iDisplayLength:10,iDisplayStart:0,iTabIndex:0,oClasses:{},oLanguage:{oAria:{sSortAscending:": activate to sort column ascending",sSortDescending:": activate to sort column descending"},oPaginate:{sFirst:"First",sLast:"Last",sNext:"Next",sPrevious:"Previous"},sEmptyTable:"No data available in table",sInfo:"Showing _START_ to _END_ of _TOTAL_ entries",sInfoEmpty:"Showing 0 to 0 of 0 entries", +sInfoFiltered:"(filtered from _MAX_ total entries)",sInfoPostFix:"",sDecimal:"",sThousands:",",sLengthMenu:"Show _MENU_ entries",sLoadingRecords:"Loading...",sProcessing:"",sSearch:"Search:",sSearchPlaceholder:"",sUrl:"",sZeroRecords:"No matching records found"},oSearch:l.extend({},u.models.oSearch),sAjaxDataProp:"data",sAjaxSource:null,sDom:"lfrtip",searchDelay:null,sPaginationType:"simple_numbers",sScrollX:"",sScrollXInner:"",sScrollY:"",sServerMethod:"GET",renderer:null,rowId:"DT_RowId"};E(u.defaults); +u.defaults.column={aDataSort:null,iDataSort:-1,asSorting:["asc","desc"],bSearchable:!0,bSortable:!0,bVisible:!0,fnCreatedCell:null,mData:null,mRender:null,sCellType:"td",sClass:"",sContentPadding:"",sDefaultContent:null,sName:"",sSortDataType:"std",sTitle:null,sType:null,sWidth:null};E(u.defaults.column);u.models.oSettings={oFeatures:{bAutoWidth:null,bDeferRender:null,bFilter:null,bInfo:null,bLengthChange:null,bPaginate:null,bProcessing:null,bServerSide:null,bSort:null,bSortMulti:null,bSortClasses:null, +bStateSave:null},oScroll:{bCollapse:null,iBarWidth:0,sX:null,sXInner:null,sY:null},oLanguage:{fnInfoCallback:null},oBrowser:{bScrollOversize:!1,bScrollbarLeft:!1,bBounding:!1,barWidth:0},ajax:null,aanFeatures:[],aoData:[],aiDisplay:[],aiDisplayMaster:[],aIds:{},aoColumns:[],aoHeader:[],aoFooter:[],oPreviousSearch:{},aoPreSearchCols:[],aaSorting:null,aaSortingFixed:[],asStripeClasses:null,asDestroyStripes:[],sDestroyWidth:0,aoRowCallback:[],aoHeaderCallback:[],aoFooterCallback:[],aoDrawCallback:[], +aoRowCreatedCallback:[],aoPreDrawCallback:[],aoInitComplete:[],aoStateSaveParams:[],aoStateLoadParams:[],aoStateLoaded:[],sTableId:"",nTable:null,nTHead:null,nTFoot:null,nTBody:null,nTableWrapper:null,bDeferLoading:!1,bInitialised:!1,aoOpenRows:[],sDom:null,searchDelay:null,sPaginationType:"two_button",iStateDuration:0,aoStateSave:[],aoStateLoad:[],oSavedState:null,oLoadedState:null,sAjaxSource:null,sAjaxDataProp:null,jqXHR:null,json:q,oAjaxData:q,fnServerData:null,aoServerParams:[],sServerMethod:null, +fnFormatNumber:null,aLengthMenu:null,iDraw:0,bDrawing:!1,iDrawError:-1,_iDisplayLength:10,_iDisplayStart:0,_iRecordsTotal:0,_iRecordsDisplay:0,oClasses:{},bFiltered:!1,bSorted:!1,bSortCellsTop:null,oInit:null,aoDestroyCallback:[],fnRecordsTotal:function(){return"ssp"==Q(this)?1*this._iRecordsTotal:this.aiDisplayMaster.length},fnRecordsDisplay:function(){return"ssp"==Q(this)?1*this._iRecordsDisplay:this.aiDisplay.length},fnDisplayEnd:function(){var a=this._iDisplayLength,b=this._iDisplayStart,c=b+ +a,d=this.aiDisplay.length,e=this.oFeatures,h=e.bPaginate;return e.bServerSide?!1===h||-1===a?b+d:Math.min(b+a,this._iRecordsDisplay):!h||c>d||-1===a?d:c},oInstance:null,sInstance:null,iTabIndex:0,nScrollHead:null,nScrollFoot:null,aLastSort:[],oPlugins:{},rowIdFn:null,rowId:null};u.ext=M={buttons:{},classes:{},builder:"-source-",errMode:"alert",feature:[],search:[],selector:{cell:[],column:[],row:[]},internal:{},legacy:{ajax:null},pager:{},renderer:{pageButton:{},header:{}},order:{},type:{detect:[], +search:{},order:{}},_unique:0,fnVersionCheck:u.fnVersionCheck,iApiIndex:0,oJUIClasses:{},sVersion:u.version};l.extend(M,{afnFiltering:M.search,aTypes:M.type.detect,ofnSearch:M.type.search,oSort:M.type.order,afnSortData:M.order,aoFeatures:M.feature,oApi:M.internal,oStdClasses:M.classes,oPagination:M.pager});l.extend(u.ext.classes,{sTable:"dataTable",sNoFooter:"no-footer",sPageButton:"paginate_button",sPageButtonActive:"current",sPageButtonDisabled:"disabled",sStripeOdd:"odd",sStripeEven:"even",sRowEmpty:"dataTables_empty", +sWrapper:"dataTables_wrapper",sFilter:"dataTables_filter",sInfo:"dataTables_info",sPaging:"dataTables_paginate paging_",sLength:"dataTables_length",sProcessing:"dataTables_processing",sSortAsc:"sorting_asc",sSortDesc:"sorting_desc",sSortable:"sorting",sSortableAsc:"sorting_desc_disabled",sSortableDesc:"sorting_asc_disabled",sSortableNone:"sorting_disabled",sSortColumn:"sorting_",sFilterInput:"",sLengthSelect:"",sScrollWrapper:"dataTables_scroll",sScrollHead:"dataTables_scrollHead",sScrollHeadInner:"dataTables_scrollHeadInner", +sScrollBody:"dataTables_scrollBody",sScrollFoot:"dataTables_scrollFoot",sScrollFootInner:"dataTables_scrollFootInner",sHeaderTH:"",sFooterTH:"",sSortJUIAsc:"",sSortJUIDesc:"",sSortJUI:"",sSortJUIAscAllowed:"",sSortJUIDescAllowed:"",sSortJUIWrapper:"",sSortIcon:"",sJUIHeader:"",sJUIFooter:""});var ic=u.ext.pager;l.extend(ic,{simple:function(a,b){return["previous","next"]},full:function(a,b){return["first","previous","next","last"]},numbers:function(a,b){return[Ea(a,b)]},simple_numbers:function(a,b){return["previous", +Ea(a,b),"next"]},full_numbers:function(a,b){return["first","previous",Ea(a,b),"next","last"]},first_last_numbers:function(a,b){return["first",Ea(a,b),"last"]},_numbers:Ea,numbers_length:7});l.extend(!0,u.ext.renderer,{pageButton:{_:function(a,b,c,d,e,h){var f=a.oClasses,g=a.oLanguage.oPaginate,k=a.oLanguage.oAria.paginate||{},m,n,p=0,t=function(x,w){var r,C=f.sPageButtonDisabled,G=function(I){Ta(a,I.data.action,!0)};var ba=0;for(r=w.length;ba ").appendTo(x);t(O,L)}else{m=null;n=L;O=a.iTabIndex;switch(L){case "ellipsis":x.append('…');break;case "first":m=g.sFirst;0===e&&(O=-1,n+=" "+C);break;case "previous":m=g.sPrevious;0===e&&(O=-1,n+=" "+C);break;case "next":m=g.sNext;if(0===h||e===h-1)O=-1,n+=" "+C;break;case "last":m=g.sLast;if(0===h||e===h-1)O=-1,n+=" "+C;break;default:m=a.fnFormatNumber(L+1),n=e===L?f.sPageButtonActive:""}null!==m&&(O=l("",{"class":f.sPageButton+" "+n,"aria-controls":a.sTableId, +"aria-label":k[L],"data-dt-idx":p,tabindex:O,id:0===c&&"string"===typeof L?a.sTableId+"_"+L:null}).html(m).appendTo(x),sb(O,{action:L},G),p++)}}};try{var v=l(b).find(A.activeElement).data("dt-idx")}catch(x){}t(l(b).empty(),d);v!==q&&l(b).find("[data-dt-idx="+v+"]").trigger("focus")}}});l.extend(u.ext.type.detect,[function(a,b){b=b.oLanguage.sDecimal;return yb(a,b)?"num"+b:null},function(a,b){if(a&&!(a instanceof Date)&&!Dc.test(a))return null;b=Date.parse(a);return null!==b&&!isNaN(b)||aa(a)?"date": +null},function(a,b){b=b.oLanguage.sDecimal;return yb(a,b,!0)?"num-fmt"+b:null},function(a,b){b=b.oLanguage.sDecimal;return pc(a,b)?"html-num"+b:null},function(a,b){b=b.oLanguage.sDecimal;return pc(a,b,!0)?"html-num-fmt"+b:null},function(a,b){return aa(a)||"string"===typeof a&&-1!==a.indexOf("<")?"html":null}]);l.extend(u.ext.type.search,{html:function(a){return aa(a)?a:"string"===typeof a?a.replace(mc," ").replace(Ya,""):""},string:function(a){return aa(a)?a:"string"===typeof a?a.replace(mc," "): +a}});var Xa=function(a,b,c,d){if(0!==a&&(!a||"-"===a))return-Infinity;b&&(a=oc(a,b));a.replace&&(c&&(a=a.replace(c,"")),d&&(a=a.replace(d,"")));return 1*a};l.extend(M.type.order,{"date-pre":function(a){a=Date.parse(a);return isNaN(a)?-Infinity:a},"html-pre":function(a){return aa(a)?"":a.replace?a.replace(/<.*?>/g,"").toLowerCase():a+""},"string-pre":function(a){return aa(a)?"":"string"===typeof a?a.toLowerCase():a.toString?a.toString():""},"string-asc":function(a,b){return ab?1:0},"string-desc":function(a, +b){return ab?-1:0}});bb("");l.extend(!0,u.ext.renderer,{header:{_:function(a,b,c,d){l(a.nTable).on("order.dt.DT",function(e,h,f,g){a===h&&(e=c.idx,b.removeClass(d.sSortAsc+" "+d.sSortDesc).addClass("asc"==g[e]?d.sSortAsc:"desc"==g[e]?d.sSortDesc:c.sSortingClass))})},jqueryui:function(a,b,c,d){l("").addClass(d.sSortJUIWrapper).append(b.contents()).append(l("").addClass(d.sSortIcon+" "+c.sSortingClassJUI)).appendTo(b);l(a.nTable).on("order.dt.DT",function(e,h,f,g){a===h&&(e=c.idx, +b.removeClass(d.sSortAsc+" "+d.sSortDesc).addClass("asc"==g[e]?d.sSortAsc:"desc"==g[e]?d.sSortDesc:c.sSortingClass),b.find("span."+d.sSortIcon).removeClass(d.sSortJUIAsc+" "+d.sSortJUIDesc+" "+d.sSortJUI+" "+d.sSortJUIAscAllowed+" "+d.sSortJUIDescAllowed).addClass("asc"==g[e]?d.sSortJUIAsc:"desc"==g[e]?d.sSortJUIDesc:c.sSortingClassJUI))})}}});var $a=function(a){Array.isArray(a)&&(a=a.join(","));return"string"===typeof a?a.replace(/&/g,"&").replace(/ h?"-":"",g=parseFloat(h);if(isNaN(g))return $a(h);g=g.toFixed(c);h=Math.abs(g);g=parseInt(h,10);h=c?b+(h-g).toFixed(c).substring(2):"";0===g&&0===parseFloat(h)&&(f="");return f+(d||"")+g.toString().replace(/\B(?=(\d{3})+(?!\d))/g,a)+h+(e||"")}}},text:function(){return{display:$a,filter:$a}}}; +l.extend(u.ext.internal,{_fnExternApiFunc:lc,_fnBuildAjax:Qa,_fnAjaxUpdate:Kb,_fnAjaxParameters:Tb,_fnAjaxUpdateDraw:Ub,_fnAjaxDataSrc:za,_fnAddColumn:cb,_fnColumnOptions:Ia,_fnAdjustColumnSizing:sa,_fnVisibleToColumnIndex:ta,_fnColumnIndexToVisible:ua,_fnVisbleColumns:na,_fnGetColumns:Ka,_fnColumnTypes:eb,_fnApplyColumnDefs:Hb,_fnHungarianMap:E,_fnCamelToHungarian:P,_fnLanguageCompat:la,_fnBrowserDetect:Fb,_fnAddData:ia,_fnAddTr:La,_fnNodeToDataIndex:function(a,b){return b._DT_RowIndex!==q?b._DT_RowIndex: +null},_fnNodeToColumnIndex:function(a,b,c){return l.inArray(c,a.aoData[b].anCells)},_fnGetCellData:T,_fnSetCellData:Ib,_fnSplitObjNotation:hb,_fnGetObjectDataFn:ma,_fnSetObjectDataFn:ha,_fnGetDataMaster:ib,_fnClearTable:Ma,_fnDeleteIndex:Na,_fnInvalidate:va,_fnGetRowElements:gb,_fnCreateTr:fb,_fnBuildHead:Jb,_fnDrawHead:xa,_fnDraw:ja,_fnReDraw:ka,_fnAddOptionsHtml:Mb,_fnDetectHeader:wa,_fnGetUniqueThs:Pa,_fnFeatureHtmlFilter:Ob,_fnFilterComplete:ya,_fnFilterCustom:Xb,_fnFilterColumn:Wb,_fnFilter:Vb, +_fnFilterCreateSearch:nb,_fnEscapeRegex:ob,_fnFilterData:Yb,_fnFeatureHtmlInfo:Rb,_fnUpdateInfo:ac,_fnInfoMacros:bc,_fnInitialise:Aa,_fnInitComplete:Ra,_fnLengthChange:pb,_fnFeatureHtmlLength:Nb,_fnFeatureHtmlPaginate:Sb,_fnPageChange:Ta,_fnFeatureHtmlProcessing:Pb,_fnProcessingDisplay:V,_fnFeatureHtmlTable:Qb,_fnScrollDraw:Ja,_fnApplyToChildren:da,_fnCalculateColumnWidths:db,_fnThrottle:mb,_fnConvertToWidth:cc,_fnGetWidestNode:dc,_fnGetMaxLenString:ec,_fnStringToCss:K,_fnSortFlatten:oa,_fnSort:Lb, +_fnSortAria:gc,_fnSortListener:rb,_fnSortAttachListener:kb,_fnSortingClasses:Va,_fnSortData:fc,_fnSaveState:Da,_fnLoadState:hc,_fnImplementState:tb,_fnSettingsFromNode:Wa,_fnLog:ea,_fnMap:Y,_fnBindAction:sb,_fnCallbackReg:R,_fnCallbackFire:F,_fnLengthOverflow:qb,_fnRenderer:lb,_fnDataSource:Q,_fnRowAttributes:jb,_fnExtend:ub,_fnCalculateEnd:function(){}});l.fn.dataTable=u;u.$=l;l.fn.dataTableSettings=u.settings;l.fn.dataTableExt=u.ext;l.fn.DataTable=function(a){return l(this).dataTable(a).api()}; +l.each(u,function(a,b){l.fn.DataTable[a]=b});return u}); diff --git a/lib/highlight.js-6.2/LICENSE b/lib/highlight.js-6.2/LICENSE new file mode 100644 index 0000000..fe2f67b --- /dev/null +++ b/lib/highlight.js-6.2/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2006, Ivan Sagalaev +All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of highlight.js nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/highlight.js-6.2/highlight.pack.js b/lib/highlight.js-6.2/highlight.pack.js new file mode 100644 index 0000000..6687e55 --- /dev/null +++ b/lib/highlight.js-6.2/highlight.pack.js @@ -0,0 +1 @@ +var hljs=new function(){function m(p){return p.replace(/&/gm,"&").replace(/"}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event=="start"){z+=t(v.node);s.push(v.node)}else{if(v.event=="stop"){var p,r=s.length;do{r--;p=s[r];z+=(""+p.nodeName.toLowerCase()+">")}while(p!=v.node);s.splice(r,1);while(r '+M[0]+""}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&&e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?'':"";if(M.rB){y+=L;M.buffer=""}else{if(M.eB){y+=m(r)+L;M.buffer=""}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?"":"";if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L>1){O=D[D.length-2].cN?"":"";y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer="";if(r.starts){I(r.starts,"")}return R.rE}if(w(M,R)){throw"Illegal"}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y="";try{var s,u=0;E.dM.buffer="";do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length>1){throw"Illegal"}return{r:A,keyword_count:x,value:y}}catch(H){if(H=="Illegal"){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r>r.keyword_count+r.r){r=s}if(s.keyword_count+s.r>p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((<[^>]+>|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,"
")}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement("pre");s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match("(\\s|^)(language-)?"+v+"(\\s|$)")){u=u?(u+" "+v):v}if(/MSIE [678]/.test(navigator.userAgent)&&t.tagName=="CODE"&&t.parentNode.tagName=="PRE"){s=t.parentNode;var p=document.createElement("div");p.innerHTML="";t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName("pre");for(var p=0;p"+y.value+"
|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.ER="(?![\\s\\S])";this.BE={b:"\\\\.",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE],r:0};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE],r:0};this.CLCM={cN:"comment",b:"//",e:"$"};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.BNM={cN:"number",b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.css=function(){var a={cN:"function",b:hljs.IR+"\\(",e:"\\)",c:[{eW:true,eE:true,c:[hljs.NM,hljs.ASM,hljs.QSM]}]};return{cI:true,dM:{i:"[=/|']",c:[hljs.CBLCLM,{cN:"id",b:"\\#[A-Za-z0-9_-]+"},{cN:"class",b:"\\.[A-Za-z0-9_-]+",r:0},{cN:"attr_selector",b:"\\[",e:"\\]",i:"$"},{cN:"pseudo",b:":(:)?[a-zA-Z0-9\\_\\-\\+\\(\\)\\\"\\']+"},{cN:"at_rule",b:"@(font-face|page)",l:"[a-z-]+",k:{"font-face":1,page:1}},{cN:"at_rule",b:"@",e:"[{;]",eE:true,k:{"import":1,page:1,media:1,charset:1},c:[a,hljs.ASM,hljs.QSM,hljs.NM]},{cN:"tag",b:hljs.IR,r:0},{cN:"rules",b:"{",e:"}",i:"[^\\s]",r:0,c:[hljs.CBLCLM,{cN:"rule",b:"[^\\s]",rB:true,e:";",eW:true,c:[{cN:"attribute",b:"[A-Z\\_\\.\\-]+",e:":",eE:true,i:"[^\\s]",starts:{cN:"value",eW:true,eE:true,c:[a,hljs.NM,hljs.QSM,hljs.ASM,hljs.CBLCLM,{cN:"hexcolor",b:"\\#[0-9A-F]+"},{cN:"important",b:"!important"}]}}]}]}]}}}();hljs.LANGUAGES.javascript={dM:{k:{keyword:{"in":1,"if":1,"for":1,"while":1,"finally":1,"var":1,"new":1,"function":1,"do":1,"return":1,"void":1,"else":1,"break":1,"catch":1,"instanceof":1,"with":1,"throw":1,"case":1,"default":1,"try":1,"this":1,"switch":1,"continue":1,"typeof":1,"delete":1},literal:{"true":1,"false":1,"null":1}},c:[hljs.ASM,hljs.QSM,hljs.CLCM,hljs.CBLCLM,hljs.CNM,{b:"("+hljs.RSR+"|\\b(case|return|throw)\\b)\\s*",k:{"return":1,"throw":1,"case":1},c:[hljs.CLCM,hljs.CBLCLM,{cN:"regexp",b:"/",e:"/[gim]*",c:[{b:"\\\\/"}]}],r:0},{cN:"function",bWK:true,e:"{",k:{"function":1},c:[{cN:"title",b:"[A-Za-z$_][0-9A-Za-z$_]*"},{cN:"params",b:"\\(",e:"\\)",c:[hljs.ASM,hljs.QSM,hljs.CLCM,hljs.CBLCLM]}]}]}};hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:"number",b:"\\b0[xX][0-9a-fA-F]+[Li]?\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\b\\d+\\.(?!\\d)(?:i\\b)?",e:hljs.IMMEDIATE_RE,r:1},{cN:"number",b:"\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"keyword",b:"(?:tryCatch|library|setGeneric|setGroupGeneric)\\b",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\.\\.\\.",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\.\\.\\d+(?![\\w.])",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\b(?:function)",e:hljs.IMMEDIATE_RE,r:2},{cN:"keyword",b:"(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"literal",b:"(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b",e:hljs.IMMEDIATE_RE,r:10},{cN:"literal",b:"(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"identifier",b:"[a-zA-Z.][a-zA-Z0-9._]*\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"operator",b:"<\\-(?!\\s*\\d)",e:hljs.IMMEDIATE_RE,r:2},{cN:"operator",b:"\\->|<\\-",e:hljs.IMMEDIATE_RE,r:1},{cN:"operator",b:"%%|~",e:hljs.IMMEDIATE_RE},{cN:"operator",b:">=|<=|==|!=|\\|\\||&&|=|\\+|\\-|\\*|/|\\^|>|<|!|&|\\||\\$|:",e:hljs.IMMEDIATE_RE,r:0},{cN:"operator",b:"%",e:"%",i:"\\n",r:1},{cN:"identifier",b:"`",e:"`",r:0},{cN:"string",b:'"',e:'"',c:[hljs.BE],r:0},{cN:"string",b:"'",e:"'",c:[hljs.BE],r:0},{cN:"paren",b:"[[({\\])}]",e:hljs.IMMEDIATE_RE,r:0}]}};hljs.LANGUAGES.xml=function(){var b="[A-Za-z0-9\\._:-]+";var a={eW:true,c:[{cN:"attribute",b:b,r:0},{b:'="',rB:true,e:'"',c:[{cN:"value",b:'"',eW:true}]},{b:"='",rB:true,e:"'",c:[{cN:"value",b:"'",eW:true}]},{b:"=",c:[{cN:"value",b:"[^\\s/>]+"}]}]};return{cI:true,dM:{c:[{cN:"pi",b:"<\\?",e:"\\?>",r:10},{cN:"doctype",b:"",r:10,c:[{b:"\\[",e:"\\]"}]},{cN:"comment",b:"",r:10},{cN:"cdata",b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{cN:"tag",b:"",rE:true,sL:"css"}},{cN:"tag",b:"