-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5b17c4a
Showing
11 changed files
with
832 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |