Skip to content

Commit

Permalink
formatP handles NA now by returning ""
Browse files Browse the repository at this point in the history
  • Loading branch information
abusjahn committed Aug 9, 2024
1 parent 5817907 commit 48cc9ad
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions R/basefunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ formatP <- function(pIn, ndigits = 3, textout = TRUE, pretext = FALSE,
formatC, format = "f",
digits = ndigits, drop0trailing = FALSE,
decimal.mark = decimal.mark
)
)|>
apply(MARGIN=c(1,2), gsub, pattern = ".*NA.*",replacement = "")
if (pretext) {
for (row_i in 1:nrow(pIn)) {
for (col_i in 1:ncol(pIn)) {
Expand All @@ -150,32 +151,45 @@ formatP <- function(pIn, ndigits = 3, textout = TRUE, pretext = FALSE,
"<", "="
),
formatp[row_i, col_i]
)
) |>
gsub(pattern = "NA.*",replacement = "", x=_)
}
}
formatp <-
apply(formatp,MARGIN=c(1,2), gsub, pattern = ".*NA.*",replacement = "")
}
if (mark) {
formatp <- matrix(
paste(
formatp,
apply(gsub("[\\<\\=]", "", formatp), c(1, 2), markSign)
apply(gsub("[\\<\\=]", "", formatp) |>
gsub(",",".",x=_), c(1, 2), markSign)
),
ncol = ncol(pIn)
)
) |> apply(MARGIN = c(1, 2),
gsub, pattern = ".*NA.*",replacement = "")
}
if(add.surprisal){
s <- apply(pIn,MARGIN = c(1,2),surprisal, precision = sprecision)
s <- apply(pIn,MARGIN = c(1,2),surprisal, precision = sprecision)
if(german_num){
s <- str_replace(s,'\\.',',')
s <- gsub('\\.',',',s)
}
for (row_i in 1:nrow(pIn)) {
for (col_i in 1:ncol(pIn)) {
formatp[row_i, col_i] <- paste0(formatp[row_i, col_i],
', s = ',s[row_i,col_i])|>
gsub(pattern = ".*NA.*",replacement = "",x=_)
}
}
formatp <- paste0(formatp,', s = ',s)
}
if (textout == FALSE & pretext == FALSE & add.surprisal == FALSE) {
formatp <- apply(formatp, MARGIN = c(1, 2), as.numeric)
}
if(!pIn_is_matrix){
formatp <- as.vector(formatp)
}
} else{
formatP=""
}
return(formatp)
}
Expand Down

0 comments on commit 48cc9ad

Please sign in to comment.