Function Name Conflicts Application uses the R documentation API to identify function conflicts (functions with same name) between two packages. For example, since function mutate is found in both plyr and dplyr, it is identified as a conflicting function. An awareness of same name functions could alleviate conflicts resulting from attachments of packages which contain those functions. This Shiny application is hosted via shinyapps.io, RStudio's hosting service for Shiny apps, accessible at Shiny Application. For full code, see GitHub.

This application uses fromJSON function from the jsonlite package for API request processing. Additional packages used for data processing are listed below.

library(jsonlite)
library(curl)
library(data.table)
library(dplyr)
library(DT)



Designing User Interface (UI)

User interface was defined using fluidPage from shiny, which creates a fluid page layout consisting of nested rows and columns. Output data tables (individual package tables and conflicting functions table) were embedded in columns. Action buttons and application background color were defined using HTML tags as shown below.

# Defining application background color
tags$head(
  tags$style(HTML("
                    body {
                    background-color: #34495E;
                    color: #ffffff;
                    }
                    "))
)

# Formatting action buttons
actionButton("package2_info", "Find Package Version", style="color: #ffffff;background-color: #212F3D;")



Calling R Documentation API

Retrieving Package Version

All versions of the selected package were first retrieved using the R documentation API to later extract metrics and functions for that package. Retrieved version text was parsed using fromJSON as shown below.

url <- paste("http://rdocumentation.org/api/packages/", input$package1, sep = "")
vers <- fromJSON(txt = url)
version1 <- vers$versions$version

After version retrieval, drop down panel for the selected package was updated using updateSelectInput(session, "packageVersion1", choices = version1, selected = "0.7.3") to reflect available version choices.



Retrieving Package Metrics and Functions

Metrics for the selected package and version were retrieved using the R documentation API. Package metrics included package name, version, title, description, release date, license, maintainer name and contact information. The retrieved metrics text was parsed using fromJSON and additionally processed as shown.

url <- paste("https://rdocumentation.org/api/packages/", input$package1, "/versions/", input$packageVersion1, sep = "")
dat <- fromJSON(txt = url)

metrics <- data.frame(dat$package_name, dat$version, dat$title, dat$description,
                      dat$release_date, dat$license, dat$maintainer$name, dat$maintainer$email)
colnames(metrics) <- c("Name", "Version", "Title", "Description", "Release Date", "License", "Maintainer", "Contact")
metrics_data <- data.frame(t(metrics))
colnames(metrics_data) <- "Package Metrics"

if (nrow(metrics_data) == 0)
{
  metrics <- data.frame("No package metrics")
  colnames(metrics) <- "Metrics"
  return(metrics)
}
else
{
  metrics_data <- setDT(data.frame(metrics_data), keep.rownames = TRUE)[]
  colnames(metrics_data) <- c("Metrics", "Description")
  return(data.frame(metrics_data))
}

In addition to package metrics, functions for the selected package were retrieved by specifying package name and version. Function name and descriptions were selected and processed using dplyr as shown.

url <- paste("https://rdocumentation.org/api/packages/", input$package1, "/versions/", input$packageVersion1, sep = "")
dat <- fromJSON(txt = url)
if (is.null(dat$topics$name) | is.null(dat$topics$title))
{
  table <- data.frame("No functions in this version of the package")
  colnames(table) <- (paste(input$package1, "Functions", sep = " "))
  return(table)
}
else
{
  packages1 <- data.frame(dat$topics$name, dat$topics$title)
  packages1 <- packages1 %>% arrange(dat$topics$name)
  colnames(packages1) <- c(paste(input$package1, "Functions", sep = " "), "Description")
  return(packages1)
}

"Function Metrics" "Function Description"


Retrieving Function Conflicts

Same name functions were obtained using the R documentations API. Function names from both user specified packages were intersected to retrieve function conflicts. Code was embedded within a progress bar to show remaining run time as shown below.

withProgress(message = "Application loading", value = 0, {
  incProgress(0.3, detail = "Loading")
  url <- paste("https://rdocumentation.org/api/packages/", input$package1, "/versions/", input$packageVersion1, sep = "")
  dat <- fromJSON(txt = url)
  packages1 <- data.frame(dat$topics$name)
  title1 <- data.frame(dat$topics$title)

  data_package1 <- cbind(packages1, title1)

  url2 <- paste("https://rdocumentation.org/api/packages/", input$package2, "/versions/", input$packageVersion2, sep = "")
  dat2 <- fromJSON(txt = url2)
  packages2 <- data.frame(dat2$topics$name)
  title2 <- data.frame(dat2$topics$title)

  data_package2 <- cbind(packages2, title2)

  inter <- intersect(packages1$dat.topics.name, packages2$dat2.topics.name)
  inter <- data.frame(inter)

  incProgress(0.7, detail = "Finishing...")
  if (nrow(inter) == 0)
  {
    inter <- data.frame("No function conflicts")
    colnames(inter) <- "Conflicts"
    return(inter)
  }
  else
  {
    inter <- data.frame(inter)
    colnames(inter) <- "dat.topics.name"
    inter$dat.topics.name <- as.character(inter$dat.topics.name)
    data_package1$dat.topics.name <- as.character(data_package1$dat.topics.name)
    data_package1$dat.topics.title <- as.character(data_package1$dat.topics.title)
    inter2 <- inter %>% inner_join(data_package1)
    data_package2 <- data_package2 %>% plyr::rename(replace = c("dat2.topics.name" = "dat.topics.name"))
    data_package2$dat.topics.name <- as.character(data_package2$dat.topics.name)
    data_package2$dat2.topics.title <- as.character(data_package2$dat2.topics.title)
    inter2 <- inter2 %>% inner_join(data_package2)
    colnames(inter2) <- c("Conflicts", paste(input$package1, "Description", sep = " "), paste(input$package2, "Description", sep = " "))
    inter2 <- inter2 %>% arrange(Conflicts)
    return(inter2)
  }
})

"Function Conflicts"