Skip to content

Commit

Permalink
Merge pull request #1458 from dbetebenner/master
Browse files Browse the repository at this point in the history
Update of startup message.
  • Loading branch information
dbetebenner authored Nov 22, 2024
2 parents 934768b + 34cf38f commit eb913cf
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 50 deletions.
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors:
- family-names: "Shang"
given-names: "Yi"
title: "SGP: Student Growth Percentiles & Percentile Growth Trajectories"
version: 2.2-0.4
version: 2.2-0.7
doi: 10.5281/zenodo.13921157
date-released: 2024-10-23
date-released: 2024-11-22
url: "https://sgp.io"
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: SGP
Type: Package
Title: Student Growth Percentiles & Percentile Growth Trajectories
Version: 2.2-0.6
Date: 2024-10-26
Version: 2.2-0.7
Date: 2024-11-22
Authors@R: c(person(given=c("Damian", "W."), family="Betebenner", email="[email protected]", role=c("aut", "cre"), comment=c(ORCID = "0000-0003-0476-5599")),
person(given=c("Adam", "R."), family="Van Iwaarden", email="[email protected]", role="aut"),
person(given="Ben", family="Domingue", email="[email protected]", role="aut"),
Expand Down
70 changes: 34 additions & 36 deletions R/capwords.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
`capwords` <-
function(x,
special.words = c("ELA","I", "II", "III", "IV", "CCSD", "CUSD", "CUD", "USD", "PSD", "UD", "ESD", "DCYF", "EMH", "HS", "MS", "ES", "SES", "IEP", "ELL", "MAD", "PARCC", "SBAC", "SD", "SWD", "US", "SGP", "SIMEX", "SS", "SAT", "PSAT", "WIDA", "ACCESS", "WIDA-ACCESS")) {
`capwords` <-
function(
x,
special.words = c("ELA", "I", "II", "III", "IV", "CCSD", "CUSD", "CUD", "USD", "PSD", "UD", "ESD", "DCYF", "EMH", "HS", "MS", "ES", "SES", "IEP", "ELL", "MAD", "PARCC", "SBAC", "SD", "SWD", "US", "SGP", "SIMEX", "SS", "SAT", "PSAT", "WIDA", "ACCESS", "WIDA-ACCESS")
) {
if (is.null(x)) return(NULL)
if (is.na(x)) return(NA)
if (identical(x, " ")) return(" ")

# Basic cleaning: replace underscores, periods, and extra spaces
x <- gsub("[_.]", " ", x)
x <- gsub("\\s+", " ", trimws(x)) # Trim and reduce multiple spaces

if (is.null(x)) return(NULL)
if (is.na(x)) return(NA)
if (identical(x, " ")) return(" ")
x <- gsub("_", " ", x)
x <- gsub("[.]", " ", x)
x <- gsub("^ *|(?<= ) | *$", "", x, perl=T)
x <- gsub("[(]", "( ", x)
x <- gsub("[)]", " )", x)
# Helper function to capitalize while respecting special words and numbers
capitalize_words <- function(word) {
# Handle special words
if (word %in% special.words) {
return(word)
} else if (grepl("^[0-9]+(\\.[0-9]+)?$", word)) { # Check for numbers
return(word)
} else {
# Capitalize the first letter only
return(paste0(toupper(substring(word, 1, 1)), tolower(substring(word, 2))))
}
}

if (identical(x, "")) {
return("")
} else {
my.split <- function(words, split.character) {
test.numeric <- function(tmp.x) grepl("[-]?[0-9]+[.]?[0-9]*|[-]?[0-9]+[L]?|[-]?[0-9]+[.]?[0-9]*[eE][0-9]+", tmp.x)
tmp.split <- unlist(strsplit(words, split=split.character))
tmp.split.special.words.index <- which(!tmp.split %in% special.words)
if (any(test.numeric(tmp.split))) tmp.split.special.words.index <- setdiff(tmp.split.special.words.index, which(test.numeric(tmp.split)))
return(list(tmp.split=tmp.split, tmp.split.special.words.index=tmp.split.special.words.index))
}
s <- my.split(x, " ")
s[[1L]][s[[2L]]] <- paste0(toupper(substring(s[[1L]][s[[2L]]],1L,1L)), tolower(substring(s[[1L]][s[[2L]]],2L)))
s.new <- paste(s[[1L]], collapse=" ")
s.new <- unlist(strsplit(s.new, split="-"))
if (length(s.new) > 1L) s.new <- paste0(toupper(substring(s.new,1L,1L)), substring(s.new,2L), collapse="-")
if (length(unlist(strsplit(s.new, split="'"))) > 1L & nchar(unlist(strsplit(s.new, split="'"))[2L]) > 1L) {
s.new <- unlist(strsplit(s.new, split="'"))
s.new <- paste0(toupper(substring(s.new,1L,1L)), substring(s.new,2L), collapse="'")
}
s.new <- unlist(strsplit(s.new, split="[.]"))
if (length(s.new) > 1L) s.new <- paste0(toupper(substring(s.new,1L,1L)), substring(s.new,2L), collapse=".")
s.new <- gsub(" [)]", ")", gsub("[(] ", "(", s.new))
return(s.new)
}
} ### END capwords
# Split words and process each, handling punctuation (hyphens, apostrophes)
words <- unlist(strsplit(x, "(?=[\\s'-])|(?<=[\\s'-])", perl = TRUE))
result <- sapply(words, capitalize_words)

# Combine processed words and fix spacing around punctuation
s.new <- paste(result, collapse = "")
s.new <- gsub("\\s+([)-])", "\\1", gsub("([(])\\s+", "\\1", s.new))

return(s.new)
} ### END capwords
3 changes: 2 additions & 1 deletion R/createSuperCohortData.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function(
setkey(tmp.dt, YEAR, GRADE, ID)
tmp.dt <- tmp.dt[unique(tmp.dt[, .(YEAR, GRADE, ID)]), mult="last"] ### Remove duplicates created by collapsing data into YEAR_NEW taking LAST (most recent) case
}

tmp.cohort.list[[paste(sgp.config.iter[['sgp.content.areas']][1], paste(sgp.config.iter[['sgp.grade.sequences']], collapse=""), sep="_")]] <- tmp.dt
}
return(rbindlist(tmp.cohort.list))
} ### END createSuperCohortData
} ### END createSuperCohortData
20 changes: 15 additions & 5 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ function(libname, pkgname) {
utils::globalVariables(c("."))
}

.onAttach <- function(libname, pkgname) {
if (interactive()) {
# Extract version information
version <- utils::packageVersion("SGP")

`.onAttach` <-
function(libname, pkgname) {
if (interactive()) {
packageStartupMessage(magenta$bold('SGP',paste(paste0(unlist(strsplit(as.character(packageVersion("SGP")), "[.]")), c(".", "-", ".", "")), collapse=""),' (10-26-2024). For help: >help("SGP") or visit sgp.io'))
}
# Define a friendly startup message
message_text <- paste0(
magenta(bold("🎉 SGP v", version)), " - ", toOrdinal::toOrdinalDate(as.character(Sys.Date())), "\n",
"💡 Tip: ", magenta(bold("> help(\"SGP\")")), "\n",
"🌐 Docs: ", magenta(bold("https://sgp.io/")), "\n",
"✨ Happy SGPing!"
)

# Display the startup message
packageStartupMessage(message_text)
}
}
4 changes: 2 additions & 2 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ bibentry(
person(given = c("Yi"), family = "Shang")
),
year = "2024",
note = "R package version 2.2-0.6",
note = "R package version 2.2-0.7",
url = "https://sgp.io",
textVersion = paste(
"Damian W. Betebenner, Adam R. Van Iwaarden, Benjamin Domingue and Yi Shang (2024).",
"SGP: Student Growth Percentiles & Percentile Growth Trajectories.",
"(R package version 2.2-0.6)",
"(R package version 2.2-0.7)",
"URL: https://sgp.io"
)
)
4 changes: 2 additions & 2 deletions man/SGP-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ growth projections to be calculated across assessment transitions by equating th
\tabular{ll}{
Package: \tab SGP\cr
Type: \tab Package\cr
Version: \tab 2.2-0.6\cr
Date: \tab 2024-10-26\cr
Version: \tab 2.2-0.7\cr
Date: \tab 2024-11-22\cr
License: \tab GPL-3\cr
LazyLoad: \tab yes\cr
}
Expand Down

0 comments on commit eb913cf

Please sign in to comment.