Assignment 10

 

Assignment 10: Building Your Own R Package

Objectives

The Premitha package is an R package designed to simplify common data analysis and visualization tasks. It is intended for students, researchers, and analysts who want to quickly explore datasets, summarize numeric variables, and create basic plots without writing repetitive code.

R Code

# Step 0: Install tools
install.packages("devtools")
install.packages("roxygen2")
library(devtools)
library(roxygen2)

# Step 1: Create your package
setwd("/Users/premithapagadala/Documents/R_Programming_Fall2025_Pagadala_Premitha/Assignments/Assignment_10_Create_Package")
create("Premitha")
setwd("Premitha") #working directory inside your package

# Step 2: Write DESCRIPTION file
desc_lines <- '
Package: Premitha
Title: Simple Tools for Streamlined Data Analysis
Version: 0.0.0.9000
Authors@R: 
    person("Premitha", "Pagadala", 
           email = "premithapagadala@gmail.com", 
           role = c("aut", "cre"))
Description: 
    The Premitha package provides simple, easy-to-use helper functions 
    that make common data analysis tasks faster and more efficient. 
    It is designed for students, researchers, and analysts who want 
    to perform exploratory data analysis and visualization quickly 
    without repetitive coding.
Depends: R (>= 3.1.2)
Imports: 
    ggplot2,
    dplyr
License: CC0
LazyData: true
URL: https://github.com/premitha27/R_Programming_Fall2025_Pagadala_Premitha
BugReports: https://github.com/premitha27/R_Programming_Fall2025_Pagadala_Premitha/issues
Suggests: knitr, rmarkdown
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.3
'

writeLines(desc_lines, "DESCRIPTION")

# Step 3: Create your first R function file 
# Create file in R/ folder and write your function
dir.create("R", showWarnings = FALSE)

function_code <- '
#\' Quick Summary and Visualization
#\'
#\' Generates a summary and a histogram for a numeric variable in a data frame.
#\' @param data A data frame containing the variable.
#\' @param var The name of the numeric variable (unquoted).
#\' @return Prints summary statistics and displays a histogram.
#\' @examples
#\' quick_summary_plot(mtcars, mpg)
#\' @export
quick_summary_plot <- function(data, var) {
  variable <- dplyr::pull(data, {{ var }})
  
  cat("Summary statistics for", deparse(substitute(var)), ":\n")
  print(summary(variable))
  
  print(
    ggplot2::ggplot(data, ggplot2::aes(x = {{ var }})) +
      ggplot2::geom_histogram(binwidth = diff(range(variable))/30, 
                              fill = "skyblue", color = "white") +
      ggplot2::theme_minimal() +
      ggplot2::labs(title = paste("Histogram of", deparse(substitute(var))))
  )
}
'
writeLines(function_code, "R/quick_summary_plot.R")

# Step 4: Document, check, and build package
document()  # Generates NAMESPACE and man/ documentation
check()     # Validates package structure
build()     # Creates .tar.gz file (installable package)

# Step 5: Install your package from GitHub 
# (After pushing it to GitHub)
# devtools::install_github("premitha-pagadala/Premitha")

# Step 6: Test your function
library(Premitha)
quick_summary_plot(mtcars, mpg)

Purpose and Scope

Premitha’s primary goal is to streamline exploratory data analysis (EDA) for numeric data. The package provides functions that generate summary statistics and visualizations, helping users quickly understand the structure, distribution, and key characteristics of their data. Its lightweight design and minimal dependencies ensure smooth performance and compatibility across most R versions.

This package is ideal for:

  • Students learning data analysis in R

  • Researchers conducting preliminary data exploration

  • Analysts needing quick summaries of datasets

By focusing on simplicity and readability, Premitha reduces the time needed to perform routine analysis tasks while providing high-quality outputs.

Key Functions

1. quick_summary_plot()

The main function in Premitha is quick_summary_plot(). It provides a one-line summary and histogram for a numeric variable in a data frame.

Parameters:

  • data: The data frame containing the variable.

  • var: The numeric variable (unquoted).

Output:

  • Prints summary statistics (minimum, 1st quartile, median, mean, 3rd quartile, maximum).

  • Displays a histogram of the variable.

Example:

library(Premitha) quick_summary_plot(mtcars, mpg)

Output:

The histogram generated allows users to visually inspect the distribution of the variable at a glance. Future updates will include additional functions for boxplots, correlation matrices, and automated data cleaning summaries.

DESCRIPTION File Choices

The DESCRIPTION file contains the metadata R needs to install, check, and document the package. Here’s a summary of the fields and why they were chosen:

  • Package Name: Premitha — uniquely identifies the package.

  • Title: “Simple Tools for Streamlined Data Analysis” — short and descriptive.

  • Version: 0.0.0.9000 — indicates a development version.

  • Authors@R: person("Premitha", "Pagadala", email="premithapagadala@gmail.com", role=c("aut","cre")) — I am the author and maintainer.

  • Description: Explains the purpose and audience of the package.

  • Depends: R (>= 3.1.2) — ensures compatibility with current R versions.

  • Imports: ggplot2 and dplyr — required for plotting and data manipulation.

  • License: CC0 — allows free use and distribution.

  • LazyData: True — if datasets are included in the future.

  • URL & BugReports: Links to GitHub repository and issue tracker.

  • Suggests: knitr and rmarkdown — useful for building vignettes.

  • Encoding & Roxygen: UTF-8 and markdown formatting for documentation.

Summary

The Premitha package demonstrates the essentials of R package development, including proper use of metadata in DESCRIPTION, documentation with roxygen2, and publishing on GitHub. The quick_summary_plot() function provides immediate insight into numeric variables, making it a useful tool for learning and performing exploratory data analysis.

Comments

Popular posts from this blog

Assignment 5

Assignment 6

Assignment 2