Commit b33474c9 authored by Quentin Read's avatar Quentin Read
Browse files

Make into an R package

parent 2b79efa7
notes/
^.*\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
.Rproj.user
.Rhistory
.RData
.Ruserdata
Package: Rutilitybelt
Title: Miscellaneous SESYNC Cyberhelp R Functions
Version: 0.0.0.9000
Authors@R:
person(given = "Quentin",
family = "Read",
role = c("aut", "cre"),
email = "qread@sesync.org")
Description: Some miscellaneous helpful R functions put together by the SESYNC Cyberhelp team for themselves and SESYNC users.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
Imports:
data.table
YEAR: 2021
COPYRIGHT HOLDER: Rutilitybelt authors
# MIT License
Copyright (c) 2021 Rutilitybelt authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Generated by roxygen2: do not edit by hand
export(group_nest_dt)
export(read.csv.better)
export(unnest_dt)
# Define function to nest DT by group, and unnest.
# these functions were written by TS Barrett in a document available at https://osf.io/f6pxw/download
group_nest_dt <-function(dt, ..., .key = "data"){
#' Nest a data.table by group
#'
#' This function was written by TS Barrett in a document available at https://osf.io/f6pxw/download.
#'
#' @export
group_nest_dt <-function(dt, ..., .key = "data") {
stopifnot(is.data.table(dt))
by <-substitute(list(...))
......@@ -10,11 +13,16 @@ group_nest_dt <-function(dt, ..., .key = "data"){
dt
}
unnest_dt <-function(dt, col, id){
#' Unnest a nested data.table
#'
#' This function was written by TS Barrett in a document available at https://osf.io/f6pxw/download.
#'
#' @export
unnest_dt <-function(dt, col, id) {
stopifnot(is.data.table(dt))
by <-substitute(id)
col <-substitute(unlist(col, recursive = FALSE))
dt[, eval(col), by = eval(by)]
}
\ No newline at end of file
}
# A wrapper function for read.csv that uses perl to convert any possible spaces to a single type and then reads the CSV with
# any other arguments to read.csv that you want to input.
# Example output where file_path refers to a CSV containing a single string with lots of different types of spaces, in this repo.
#' read.csv wrapper that detects all space characters
#'
#' A wrapper function for read.csv that uses perl to convert any possible spaces to a single type
#' and then reads the CSV with any other arguments to read.csv that you want to input.
#'
#' @examples
#' \dontrun{
# Bad:
# read.csv("spcs.csv", header = FALSE)
# V1
......@@ -12,7 +14,9 @@
# read.csv.better("spcs.csv", header = FALSE)
# V1
# 1 X X
#' }
#'
#' @export
read.csv.better <- function(file_path, ...) {
read.csv_args <- list(...)
txt <- system2("perl", args = paste("-CSDA -plE \"s/\\s/ /g\"", file_path), stdout = TRUE)
......
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/group_nest_dt.R
\name{group_nest_dt}
\alias{group_nest_dt}
\title{Nest a data.table by group}
\usage{
group_nest_dt(dt, ..., .key = "data")
}
\description{
This function was written by TS Barrett in a document available at https://osf.io/f6pxw/download.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/read.csv.better.R
\name{read.csv.better}
\alias{read.csv.better}
\title{read.csv wrapper that detects all space characters}
\usage{
read.csv.better(file_path, ...)
}
\description{
A wrapper function for read.csv that uses perl to convert any possible spaces to a single type
and then reads the CSV with any other arguments to read.csv that you want to input.
}
\examples{
\dontrun{
}
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/group_nest_dt.R
\name{unnest_dt}
\alias{unnest_dt}
\title{Unnest a nested data.table}
\usage{
unnest_dt(dt, col, id)
}
\description{
This function was written by TS Barrett in a document available at https://osf.io/f6pxw/download.
}
X             X
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment