Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
francojc committed Mar 10, 2024
0 parents commit 5b17c4a
Show file tree
Hide file tree
Showing 11 changed files with 832 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
^qtkit\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^README\.Rmd$
^cran-comments\.md$
^.*\.code-workspace$
^_pkgdown\.yml$
^docs$
^pkgdown$
^README\.Rmd$
^\.github$
^vignettes/articles$
^\.httr-oauth$
^\.lintr
^data-raw$

28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# RStudio
.Rproj.user
.Rhistory
.Rdata
.Ruserdata
.Renviron
*.Rproj

# VSCode
*.code-workspace
.lintr

# R
.httr-oauth
data-raw
inst/doc
vignettes/articles/_site/
vignettes/articles/data/

# GitHub Actions
.github/workflows/pkgdown.yaml

# macOS
.DS_Store

# Misc
*_cache
packages.bib
16 changes: 16 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Title: Quantitative Text Kit
Version: 0.9.4
Authors@R:
person("Jerid", "Francom", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5972-6330"))
Description: Support package for the textbook "An Introduction to
Quantitative Text Analysis for Linguists: Reproducible Research using
R".
Date: 2024-03-10
License: GPL (>= 3)
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
595 changes: 595 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(create_data_origin)
importFrom(utils,write.csv)
43 changes: 43 additions & 0 deletions R/create_data_origin.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' Create data origin file
#'
#' This function creates a data frame with attributes about the origin of the data,
#' writes it to a CSV file at the specified file path, and returns the data frame, if requested.
#'
#' @param file_path A character string specifying the file path where the data origin file should be saved.
#' @param return A logical value indicating whether the data origin should be returned.
#' @param force A logical value indicating whether to overwrite the file if it already exists.
#' @return A data frame containing the data origin information.
#' @export
#'
#' @examples
#' \dontrun{
#' create_data_origin("data_origin.csv")
#' }
#' @importFrom utils write.csv
#'
create_data_origin <- function(file_path, return = FALSE, force = FALSE) {
# Check to see if `file_path` is a character string
if (!is.character(file_path)) stop("`file_path` must be a character string.")

# Check to see if file exists at `file_path`
if (file.exists(file_path) && !force) {
stop("File already exists at `file_path`. Set `force = TRUE` to overwrite.")
}

# Create a data frame with the data origin information
data_origin <- data.frame(
attribute = c("Resource name", "Data source", "Data sampling frame", "Data collection date(s)", "Data format", "Data schema", "License", "Attribution"),
description = c("The name of the resource.", "URL, DOI, etc.", "Language, language variety, modality, genre, etc.", "The dates the data was collected.", ".txt, .csv, .xml, .html, etc.", "Relationships between data elements: files, folders, etc.", "CC BY, CC BY-SA, etc.", "Citation information.")
)

# Write the data origin to a file
write.csv(data_origin, file = file_path, row.names = FALSE)

# Return message
message("Data origin file created at `file_path`.")

# Return the data origin, if requested
if (return) {
return(data_origin)
}
}
56 changes: 56 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# qtkit

<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/qtkit)](https://CRAN.R-project.org/package=qtkit)
<!-- badges: end -->

The goal of qtkit is to ...

## Installation

You can install the development version of qtkit like so:

``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library(qtkit)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:

```{r cars}
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this.

You can also embed plots, for example:

```{r pressure, echo = FALSE}
plot(pressure)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
27 changes: 27 additions & 0 deletions man/create_data_origin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(qtkit)

test_check("qtkit")
30 changes: 30 additions & 0 deletions tests/testthat/test-create_data_origin.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
library(testthat)

create_data_origin <- function(n = 100, p = 2) {
x <- matrix(rnorm(n * p), ncol = p)
colnames(x) <- paste0("X", seq_len(ncol(x)))
y <- rnorm(n)
data.frame(y, x)
}

test_that("test create_data_origin function", {
# check if create_data_origin returns a data frame
expect_is(create_data_origin(), "data.frame")

# check if number of rows equals to n
expect_equal(nrow(create_data_origin()), 100)
expect_equal(nrow(create_data_origin(50)), 50)

# check if number of columns equals to p + 1
expect_equal(ncol(create_data_origin()), 3)
expect_equal(ncol(create_data_origin(100, 5)), 6)

# check if the first column is named y
expect_equal(colnames(create_data_origin())[1], "y")

# check if the remaining column names are correct
expect_equal(colnames(create_data_origin(100, 5))[-1], paste0("X", 1:5))

# check if data is generated using normal distribution
expect_equal(mean(create_data_origin(1000000, 1)$y) < 0.05, TRUE)
})

0 comments on commit 5b17c4a

Please sign in to comment.