Skip to content

Commit

Permalink
change kableExtra to gt
Browse files Browse the repository at this point in the history
  • Loading branch information
agricolamz committed Nov 9, 2024
1 parent 6166f64 commit 5dee280
Show file tree
Hide file tree
Showing 10 changed files with 6,502 additions and 999 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: lingglosses
Type: Package
Title: Interlinear Glossed Linguistic Examples and Abbreviation Lists Generation
Version: 0.0.7
Version: 0.0.8
Depends: R (>= 3.5.0)
Authors@R: person("George", "Moroz",
role = c("aut", "cre"),
Expand All @@ -18,7 +18,7 @@ Encoding: UTF-8
LazyData: true
URL: https://CRAN.R-project.org/package=phonfieldwork, https://agricolamz.github.io/lingglosses/
BugReports: https://github.com/agricolamz/lingglosses/issues
Imports: kableExtra, knitr, rmarkdown, utils, htmltools, methods
RoxygenNote: 7.2.3
Imports: gt, knitr, rmarkdown, utils, htmltools, methods
RoxygenNote: 7.3.2.9000
Suggests: testthat (>= 3.0.0)
Config/testthat/edition: 3
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export(convert_to_df)
export(get_examples_db)
export(gloss_example)
export(make_gloss_list)
importFrom(gt,fmt_markdown)
importFrom(gt,gt)
importFrom(gt,opt_table_lines)
importFrom(gt,tab_footnote)
importFrom(gt,tab_options)
importFrom(htmltools,a)
importFrom(htmltools,tagList)
importFrom(htmltools,tags)
importFrom(kableExtra,footnote)
importFrom(kableExtra,kable_minimal)
importFrom(kableExtra,kbl)
importFrom(knitr,asis_output)
importFrom(knitr,is_html_output)
importFrom(knitr,is_latex_output)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# lingglosses 0.0.8

- add 2PL gloss

# lingglosses 0.0.7

- fix by @yihui
Expand Down
53 changes: 27 additions & 26 deletions R/gloss_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
#'
#' @importFrom knitr is_latex_output
#' @importFrom knitr is_html_output
#' @importFrom kableExtra kable_minimal
#' @importFrom kableExtra kbl
#' @importFrom kableExtra footnote
#' @importFrom gt gt
#' @importFrom gt tab_footnote
#' @importFrom gt tab_options
#' @importFrom gt fmt_markdown
#' @importFrom gt opt_table_lines
#' @importFrom methods missingArg
#' @importFrom methods hasArg
#' @export
Expand Down Expand Up @@ -250,33 +252,41 @@ gloss_example <- function(transliteration,
result <- cbind(matrix(c("", grammaticality, "")), result)
}
}
result <- kableExtra::kbl(result, align = "l", centering = FALSE,
escape = FALSE, vline = "")
result <- kableExtra::kable_minimal(result,
position = "left",
full_width = FALSE)

result |>
as.data.frame() |>
gt::gt() |>
gt::tab_options(column_labels.hidden = TRUE,
table.align = "left") |>
gt::opt_table_lines(extent = "none") |>
gt::fmt_markdown() ->
result

# add video ---------------------------------------------------------------
if(!is.null(video_path) & knitr::is_html_output()){
if(length(video_path) > 1){
stop("video_path argument should be of the length 1")
}
result <- kableExtra::footnote(kable_input = result,
general = as.character(
result <- gt::tab_footnote(data = result,
footnote = as.character(
add_video(video_path,
video_width,
video_height)),
general_title = "",
escape = FALSE)
video_height)))
}

# add free translation -----------------------------------------------------
if(nchar(free_translation) > 0){
result <- gt::tab_footnote(data = result,
footnote = paste0("'",
free_translation,
"'"))
}


# add comment --------------------------------------------------------------
if(nchar(comment) > 0){
result <- kableExtra::footnote(kable_input = result,
general = comment,
general_title = "")
result <- gt::tab_footnote(data = result,
footnote = comment)
}

# add audio ---------------------------------------------------------------
Expand All @@ -294,15 +304,6 @@ gloss_example <- function(transliteration,
} else {
add_to_translation <- "'"
}
# add free translation -----------------------------------------------------
if(nchar(free_translation) > 0){
result <- kableExtra::footnote(kable_input = result,
general = paste0("'",
free_translation,
add_to_translation),
general_title = "",
escape = FALSE)
}

# remove lines from LaTeX --------------------------------------------------
if(knitr::is_latex_output()){
Expand All @@ -316,7 +317,7 @@ gloss_example <- function(transliteration,

# return output ------------------------------------------------------------
if(length(unique(splits_by_line)) > 1){
cat(unlist(multiline_result))
for(i in multiline_result) {print(i)}
} else{
return(result)
}
Expand Down
2 changes: 1 addition & 1 deletion R/glosses_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' Comrie, Haspelmath, and Bickel and other glosses automatically gathered from
#' Glossa Journal articles.
#'
#' @format A data frame with 1341 rows and 4 variables:
#' @format A data frame with 1342 rows and 4 variables:
#' \describe{
#' \item{gloss}{the gloss abbreviation}
#' \item{definition_en}{the gloss definition}
Expand Down
Binary file modified data/glosses_df.RData
Binary file not shown.
13 changes: 9 additions & 4 deletions database_creation/glossa.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ for_analysis %>%
# save file as rds ---------------------------------------------------------
glosses_df <- read.csv("database_creation/glosses_extracted.csv")

glosses_df %>%
count(gloss, weight, sort = TRUE) %>%
pivot_wider(names_from = weight, values_from = n) %>%
View()
library(tidyverse)
glosses_df |>
bind_rows(tibble(gloss = "2PL",
definition_en = "second person plural",
source = "lingglosses",
weight = 1)) |>
arrange(gloss) ->
glosses_df

save(glosses_df, file="data/glosses_df.RData", compress='xz')


4 changes: 1 addition & 3 deletions docs/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ gloss_example("Learn to value yourself, which means: to fight for your happiness
Sometimes examples are too long and do not fit onto the page. In that case you need to add the argument `results='asis'` to your chunk. `gloss_example()` will then automatically split your example into multiple rows.

(@tsa_ex) Mishlesh Tsakhur, East Caucasian [@maisak07: 386]
```{r, results='asis'}
```{r}
gloss_example('za-s jaːluʁ **wo-b** **qa-b-ɨ**; turs-ubɨ qal-es-di ǯiqj-eː jaːluʁ-**o-b** **qa-b-ɨ**',
'1SG.OBL-DAT shawl.3 AUX-3 PRF-3-bring.PFV woolen_sock-PL NPL.bring-PL-A.OBL place-IN shawl.3-AUX-3 PRF-3-bring.PFV',
'(they) **brought** me a shawl; instead of (lit. in place of bringing) woolen socks, (they) **brought** a shawl.',
Expand Down Expand Up @@ -318,8 +318,6 @@ The first line corresponds to pictures in markdown format that should be located

After you finished your text, it is possible to call the `make_gloss_list()` function in order to automatically create a list of abbreviations.



```{r}
make_gloss_list()
```
Expand Down
Loading

0 comments on commit 5dee280

Please sign in to comment.