autoPipeSearch: autoPipeSearch function

Description Usage Arguments Value Examples

View source: R/autoPipeSearch.R

Description

This function automatically constructs pipe for a given election.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
autoPipeSearch(
  x,
  ttime = FALSE,
  blocks = NULL,
  search.term = NULL,
  hits = 2,
  extracturls = FALSE,
  breakloop = 100,
  messages = FALSE
)

Arguments

x

url, list of urls.

ttime

checks if data covers reported turnout over election day (TRUE) or not (FALSE). ttime is valid when blocks=NULL

blocks

vector of blocks to be used to construct a pipe. blocks override ttime parameters. By default, c("listURLextractor()", "rowURLextractor('sayt izbiratel‘noy komissii sub'yekta’)", "rowURLextractor('Itogi golosovaniya|Rezul‘taty vyborov’)").

search.term

once the stop "term" is detected the algorithm stops building the pipe (by default, UIK|uik|uchastok).

hits

number of times the stop word is "hit" by the algorithm. Each time the stop word is "hit" extra block is added to the pipe (by default, hits=2).

extracturls

urls are extracted using the pipe or the list of pipes (by default, extracturls=FALSE).

breakloop

maximum number of iterations for optimal path search (by default, breakloop=100).

messages

display progress messages (messages = FALSE).

Value

Returns the list elections and pipe.table objects.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
library(CECscraper)
library(dplyr)
library(rvest)
 webpage <- read_html(system.file("elections_primorye.html", package="CECscraper"))

 #Example 1
 wterrit <- webpage %>% fileURLextractor(hashid = FALSE)
 #uik_url1 <- wterrit[1,]%>%autoPipeSearch(extracturls=TRUE, ttime=FALSE)
 uik_url1 <- wterrit[1,]%>%autoPipeSearch(ttime=TRUE)
 uik_url2 <- uik_url1%>%execPipeList()
 #uik_url3 <- uik_url2%>%dataBuilder(ttime=FALSE)
  uik_url3 <- uik_url2%>%dataBuilder(ttime=TRUE)

 #Example 2
 uik_url1 <- wterrit[1,]%>%autoPipeSearch(blocks=c("listURLextractor()",
                                                  "rowURLextractor('sayt izbiratel`noy komissii sub`yekta')",
                                                  "rowURLextractor('Svodnaya tablitsa')"),  hits=3, search.term="Svodnaya tablitsa")
 uik_url2 <- uik_url1%>%
            execPipeList()%>%
            dataBuilder(typedata = "fast")

 #Example 3
 uik_url1 <- wterrit[1,]%>%autoPipeSearch(blocks=c("listURLextractor()",
                                                  "rowURLextractor('sayt izbiratel`noy komissii sub`yekta')",
                                                  "rowURLextractor('Dannyye ob otkrytii pomeshcheniy')"),  hits=3, search.term="Dannyye ob otkrytii pomeshcheniy")
 uik_url2 <- uik_url1%>%
            execPipeList()%>%
            dataBuilder(ttime = TRUE, typedata = "fast")

 #Example 4
 uik_url1 <- wterrit[1,]%>%autoPipeSearch(blocks=c("listURLextractor()",
                                               "rowURLextractor('sayt izbiratel`noy komissii sub`yekta')",
                                               "rowURLextractor('Svedeniya o kandidatakh')"),  hits=1, search.term="Svedeniya o kandidatakh")
 uik_url2 <- uik_url1%>%
             execPipeList()%>%
             scrapeCandidates(tabextract = NULL, savetodir = "")

kkalininMI/CECscraper documentation built on Oct. 28, 2020, 1:47 a.m.