R/addTag.R

Defines functions addTag

Documented in addTag

#' Add a new html tag to tag_list
#'
#' @param tag_list list of html tags
#' @param name the name of the column that will store the
#'   tag's information in the R dataframe output by the function getData
#' @param html_tag html tag, examples: span, div, a
#' @param html_attribute the html attribute associated with the html tag, examples: class, jsname
#' @param html_attribute_value the value assigned to the attribute
#' @export
#' @examples
#' getData_SingleApp("https://play.google.com/store/apps/details?id=com.dinaga.photosecret")
#' getData_SingleApp("https://play.google.com/store/apps/details?id=com.jamezuki.hidden")


addTag <- function(tag_list=NULL, name, html_tag, html_attribute, html_attribute_value){

  # If tag_list hasn't been created yet
  if (is.null(tag_list)) {
    # create emtpy list for new tag data
    tag <- vector(mode="list", length=4)
    names(tag) <- c("name","html_tag","html_attribute","html_attribute_value")

    # add new tag data
    tag$name <- name
    tag$html_tag <- html_tag
    tag$html_attribute <- html_attribute
    tag$html_attribute_value <- html_attribute_value

    # create tag_list
    tag_list <- list(tag)

  # If tag_list already exists
  } else {
    # create emtpy list for new tag data
    tag <- vector(mode="list", length=4)
    names(tag) <- c("name","html_tag","html_attribute","html_attribute_value")

    # add new tag data
    tag$name <- name
    tag$html_tag <- html_tag
    tag$html_attribute <- html_attribute
    tag$html_attribute_value <- html_attribute_value

    # append tag to tag_list
    tag_list <- append(tag_list, list(tag))

  }

  # save updated tag_list
  save(tag_list, file="./Data/tag_list.RData")

}
stephaniereinders/RPlaystoreScraping documentation built on June 23, 2020, 11:04 a.m.