Skip to content

Commit

Permalink
cleaning up for lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonStanley committed Feb 2, 2024
1 parent 3526bc5 commit 104ae31
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 48 deletions.
50 changes: 27 additions & 23 deletions R/furniture.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
#' furniture
#'
#' The furniture package offers simple functions (i.e. pieces of furniture) and an
#' operator that are aimed at helping applied researchers explore and communicate
#' their data as well as clean their data in a tidy way. The package follows similar
#' semantics to the "tidyverse" packages. It contains several table functions (\code{table1()})
#' being the core one.
#'
#' The furniture package offers simple functions (i.e. pieces of furniture) and
#' an operator that are aimed at helping applied researchers explore and
#' communicate their data as well as clean their data in a tidy way. The package
#' follows similar semantics to the "tidyverse" packages. It contains several
#' table functions (\code{table1()}) being the core one.
#'

Check warning on line 8 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=8,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' \itemize{
#' \item \code{table1} provides a well-formatted descriptive table often seen

Check warning on line 10 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=10,col=80,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' as table 1 in academic journals (also a version that simplifies the output is
#' available as \code{simple_table1}),
#' \item \code{washer} provides a simple way to clean up data where there are placeholder
#' values, and
#' \item \code{\%xt\%} is an operator that takes two factor variables and creates a cross tabulation and
#' tests for significance via a chi-square test.
#' as table 1 in academic journals (also a version that simplifies the

Check warning on line 11 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=11,col=79,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' output is available as \code{simple_table1}),
#' \item \code{washer} provides a simple way to clean up data where there are

Check warning on line 13 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=13,col=80,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' placeholder values, and
#' \item \code{\%xt\%} is an operator that takes two factor variables and

Check warning on line 15 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=15,col=76,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' creates a cross tabulation and tests for significance via a

Check warning on line 16 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=16,col=71,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' chi-square test.
#' }
#'

Check warning on line 19 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=19,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' Table 1 is the main function in furniture. It is useful in both data exploration
#' and data communication. With minimal cleaning, the outputted table can be put into
#' an academic, peer reviewed journal manuscript. As such, it is very useful in exploring
#' your data when you have a stratifying variable. For example, if you are exploring whether
#' the means of several demographic and behavioral characteristics are related to a health condition,
#' the health condition (i.e. "yes" or "no"; "low", "mid", or "high"; or a list of conditions) as
#' the stratifying variable. With little code, you can test for associations and check means or
#' counts by the stratifying variable. See the vignette for more information.
#'
#' Note: furniture is meant to make life more comfortable and beautiful. In like manner, this package
#' is designed to be "furniture" for quantitative research.
#' Table 1 is the main function in furniture. It is useful in both data
#' exploration and data communication. With minimal cleaning, the outputted
#' table can be put into an academic, peer reviewed journal manuscript. As such,
#' it is very useful in exploring your data when you have a stratifying
#' variable. For example, if you are exploring whether the means of several
#' demographic and behavioral characteristics are related to a health condition,
#' the health condition (i.e. "yes" or "no"; "low", "mid", or "high"; or a list
#' of conditions) as the stratifying variable. With little code, you can test
#' for associations and check means or counts by the stratifying variable.
#' See the vignette for more information.

Check warning on line 29 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=29,col=42,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#'

Check warning on line 30 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=30,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' Note: furniture is meant to make life more comfortable and beautiful.
#' In like manner, this package is designed to be "furniture" for quantitative
#' research.
#'

Check warning on line 34 in R/furniture.R

View workflow job for this annotation

GitHub Actions / lint

file=R/furniture.R,line=34,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @examples
#' \dontrun{
Expand Down
55 changes: 30 additions & 25 deletions R/long_wide.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#' @title Long to Wide Data Reshaping
#' @author Tyson S. Barrett
#'
#' @description \code{wide()} is a wrapper of \code{stats::reshape()} that takes the data
#' from a long format to a wide format.
#'
#'
#' @description \code{wide()} is a wrapper of \code{stats::reshape()} that takes
#' the data from a long format to a wide format.
#'
#' @param data the data.frame containing the wide format data
#' @param v.names the variable names in quotes of the measures to be separated into multiple columns based on the time variable
#' @param v.names the variable names in quotes of the measures to be separated
#' into multiple columns based on the time variable
#' @param timevar the variable name in quotes of the time variable
#' @param id the ID variable name in quotes
#'
#'
#' @seealso \code{stats::reshape()}, \code{tidyr::spread()}
#'
#'
#' @importFrom stats reshape
#'
#'
#' @export
wide <- function(data, v.names, timevar, id=NULL){
UseMethod("wide", data)
Expand Down Expand Up @@ -71,27 +72,32 @@ wide.matrix <- function(data, v.names=NULL, timevar, id=NULL){
#' @title Wide to Long Data Reshaping
#' @author Tyson S. Barrett
#'
#' @description \code{long()} is a wrapper of \code{stats::reshape()} that takes the data
#' from a wide format to a long format. It can also handle unbalanced data (where some measures
#' have different number of "time points").
#' @description \code{long()} is a wrapper of \code{stats::reshape()} that takes
#' the data from a wide format to a long format. It can also handle unbalanced
#' data (where some measures have different number of "time points").
#'
#' @param data the data.frame containing the wide format data
#' @param ... the variables that are time-varying that are to be placed in long format,
#' needs to be in the format \code{c("x1", "x2"), c("z1", "z2"), etc.}. If the data is
#' unbalanced (e.g., there are three time points measured for one variable but only two for another),
#' using the placeholder variable \code{miss}, helps fix this.
#' @param v.names a vector of the names for the newly created variables (length same as number of vectors in \code{varying})
#' @param ... the variables that are time-varying that are to be placed in
#' long format, needs to be in the format
#' \code{c("x1", "x2"), c("z1", "z2"), etc.}. If the data is
#' unbalanced (e.g., there are three time points measured for one variable but
#' only two for another), using the placeholder variable \code{miss},
#' helps fix this.
#' @param v.names a vector of the names for the newly created variables (length
#' same as number of vectors in \code{varying})
#' @param id the ID variable in quotes
#' @param timevar the column with the "time" labels
#' @param times the labels of the \code{timevar} (default is numeric)
#' @param sep the separating character between the wide format variable names (default is \code{""}); e.g. "x1" and "x2" would create the variable name of "x"; only applicable if \code{v.names}
#'
#' @param sep the separating character between the wide format variable names
#' (default is \code{""}); e.g. "x1" and "x2" would create the variable name of
#' "x"; only applicable if \code{v.names}
#'
#' @seealso \code{stats::reshape()} and \code{sjmisc::to_long()}
#'
#' @importFrom stats reshape
#'
#'
#' @examples
#'
#'
#' x1 <- runif(1000)
#' x2 <- runif(1000)
#' x3 <- runif(1000)
Expand All @@ -101,20 +107,19 @@ wide.matrix <- function(data, v.names=NULL, timevar, id=NULL){
#' a <- factor(sample(c(1,2), 1000, replace=TRUE))
#' b <- factor(sample(c(1,2,3,4), 1000, replace=TRUE))
#' df <- data.frame(x1, x2, x3, y1, y2, z, a, b)
#'
#'
#' ## "Balanced" Data
#' ldf1 <- long(df,
#' c("x1", "x2"), c("y1", "y2"),
#' v.names = c("x", "y"))
#'
#'
#' ## "Unbalanced" Data
#' ldf2 = long(df,
#' c("x1", "x2", "x3"), c("y1", "y2", "miss"),
#' v.names = c("x", "y"))
#'
#'
#'
#'
#' @export

long <- function(data, ..., v.names=NULL, id=NULL, timevar=NULL, times=NULL, sep=""){
UseMethod("long", data)
}
Expand Down

0 comments on commit 104ae31

Please sign in to comment.