### Install dplyr if not available Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/by_cases.md Ensures the 'dplyr' package is installed before running the example. This is a common setup step for examples relying on external packages. ```r if (!requireNamespace("dplyr")) { stop("Please install the 'dplyr' package to run this example") } ``` -------------------------------- ### Generate PDF from Matrix Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/quick-output.html This example demonstrates how to quickly generate a PDF document from a matrix using the `quick_pdf` function. Ensure the `huxtable` package is installed and loaded. ```R if (FALSE) { # \dontrun{ m <- matrix(1:4, 2, 2) quick_pdf(m, jams) } ``` -------------------------------- ### Generate Typst Document from Matrix Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/quick-output.html This example demonstrates generating a Typst document from a matrix using `quick_typst`. Ensure the `typst` command-line tool is installed. ```R if (FALSE) { # \dontrun{ m <- matrix(1:4, 2, 2) quick_typst(m, jams) } ``` -------------------------------- ### Example: Set and Get Left Padding Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/padding.md Demonstrates setting the left padding of a huxtable to 2 points and then retrieving it. The output shows the updated padding values for the table. ```r left_padding(jams) <- 2 left_padding(jams) #> Type Price #> 1 2 2 #> 1.1 2 2 #> 2 2 2 #> 3 2 2 ``` -------------------------------- ### Example: Create and print a huxtable in LaTeX Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/to_latex.md This example demonstrates creating a simple huxtable and then printing its LaTeX representation using `print_latex`. ```r ht <- huxtable( a = 1:3, b = letters[1:3] ) print_latex(ht) ``` -------------------------------- ### Install R Packages with apt-get Source: https://github.com/hughjonesd/huxtable/blob/master/docs/AGENTS.md When installing large, common R packages like dplyr, it's recommended to first attempt installation using apt-get to potentially save time and resources before resorting to R's install.packages(). ```bash apt-get --no-install-recommends install r-cran-dplyr ``` -------------------------------- ### Install Optional Packages Source: https://github.com/hughjonesd/huxtable/blob/master/docs/CLAUDE.md Instructions to install optional packages listed in DESCRIPTION Suggests. This is necessary for working with certain features. ```R DESCRIPTION Suggests ``` -------------------------------- ### Install Latest Huxtable from GitHub Source: https://github.com/hughjonesd/huxtable/blob/master/README.md Install the most recent version of huxtable directly from its GitHub repository. This requires the 'remotes' package to be installed first. ```r install.packages("remotes") remotes::install_github("hughjonesd/huxtable") ``` -------------------------------- ### Example Usage of Quick Output Functions Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/quick-output.md Demonstrates how to use various `quick_` functions with a matrix object. These examples are typically run within an `if (FALSE)` block to prevent execution during package checks. ```r if (FALSE) { # \dontrun{ m <- matrix(1:4, 2, 2) quick_pdf(m, jams) quick_latex(m, jams) quick_typst(m, jams) quick_typst_pdf(m, jams) quick_typst_png(m, jams) quick_typst_svg(m, jams) quick_html(m, jams) quick_docx(m, jams) quick_xlsx(m, jams) quick_pptx(m, jams) quick_rtf(m, jams) } # } ``` -------------------------------- ### Install Specific Dependencies Source: https://github.com/hughjonesd/huxtable/blob/master/docs/CLAUDE.md Notes that packages like 'flextable' and 'lmtest' might be missing and need to be installed if working on related features. ```R flextable, lmtest ``` -------------------------------- ### Map background colors globally Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/by_colorspace.html This example demonstrates how to use `by_colorspace` to map numeric values in a huxtable to a color gradient (red to yellow to blue) for the background. It requires the 'scales' package to be installed. ```R if (!requireNamespace("scales")) { stop("Please install the \"scales\" package to run this example") } ht <- as_hux(matrix(rnorm(25), 5, 5)) map_background_color( ht, by_colorspace("red", "yellow", "blue") ) ``` -------------------------------- ### Example usage within a knitr document Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/guess_knitr_output_format.md Demonstrates how to use the function within a knitr document. This example is not run by default. ```r if (FALSE) { # \dontrun{ # in a knitr document guess_knitr_output_format() } # } ``` -------------------------------- ### Check LaTeX Dependencies Installation Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/report_latex_dependencies.md Verifies if the necessary LaTeX packages are installed on the system. Suppress messages with `quiet = TRUE`. ```r check_latex_dependencies(quiet = FALSE) ``` -------------------------------- ### Example of setting a table label Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/label.md This example demonstrates how to set a specific label, 'tab:mytable', for a huxtable named 'jams'. ```r set_label(jams, "tab:mytable") #> Type Price #> Strawberry 1.90 #> Raspberry 2.10 #> Plum 1.80 #> #> Column names: Type, Price ``` -------------------------------- ### Install Huxtable from r-universe Source: https://github.com/hughjonesd/huxtable/blob/master/README.md Use this command to install the huxtable package from the r-universe repository. Ensure you have the necessary repositories configured. ```r install.packages("huxtable", repos = c( "https://hughjonesd.r-universe.dev", "https://cloud.r-project.org" )) ``` -------------------------------- ### Print Huxtable to Screen Example Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/to_screen.md This example demonstrates how to format a huxtable with borders, bold text, and text color before printing it to the screen. The output shows the table with column names and formatted cell content. ```r bottom_border(jams)[1, 1:2] <- 1 bold(jams)[1, 1:2] <- TRUE jams <- map_text_color( jams, by_regex("berry" = "red") ) print_screen(jams) #> Type Price #> ──────────────────────── #> Strawberry 1.90 #> Raspberry 2.10 #> Plum 1.80 #> #> Column names: Type, Price ``` -------------------------------- ### Install Huxtable from CRAN Source: https://github.com/hughjonesd/huxtable/blob/master/README.md This is the standard command to install the huxtable package from the Comprehensive R Archive Network (CRAN). ```r install.packages("huxtable") ``` -------------------------------- ### Example: Set NA string for a specific cell Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/na_string.md This example demonstrates setting an NA value in a table and then changing how it is displayed using `set_na_string`. ```r jams[3, 2] <- NA jams set_na_string(jams, "---") ``` -------------------------------- ### Get and Set Table Environment Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/table_environment.md Demonstrates how to get the current table environment and how to set it using the assignment operator or the `set_table_environment` function. The value can be reset to default by setting it to NA. ```r table_environment(ht) table_environment(ht) <- value set_table_environment(ht, value) ``` -------------------------------- ### Basic Theme Example Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/themes.md Applies a standard theme with clear column separation. Suitable for general use. ```r theme_basic(jams) #> Type Price #> ──────────────────────── #> Strawberry 1.90 #> Raspberry 2.10 #> Plum 1.80 #> #> Column names: Type, Price ``` -------------------------------- ### Example of printing a huxtable as Markdown Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/to_md.html This example demonstrates how `print_md()` outputs a huxtable to the console in Markdown format. The output includes a header and formatted table data. ```R print_md(jams) #> ----------------------- #> Type Price #> ----------- ----------- #> Strawberry 1.90 #> #> Raspberry 2.10 #> #> Plum 1.80 #> ----------------------- #> ``` -------------------------------- ### Grey Theme Example Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/themes.md Applies a grey theme with subtle borders. Offers a professional and understated look. ```r theme_grey(jams) #> ┌────────────┬─────────┐ #> │ Type │ Price │ #> ├────────────┼─────────┤ #> │ Strawberry │ 1.90 │ #> ├────────────┼─────────┤ #> │ Raspberry │ 2.10 │ #> ├────────────┼─────────┤ #> │ Plum │ 1.80 │ #> └────────────┴─────────┘ #> #> Column names: Type, Price ``` -------------------------------- ### Basic Huxtable Initialization Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html Initializes a Huxtable instance with basic configuration. This is a starting point for most Huxtable implementations. ```javascript var table = new Huxtable(document.getElementById('my-table'), { // options }); ``` -------------------------------- ### Plain Theme Example Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/themes.md Applies a simple, clean theme to the table. Useful for basic data presentation. ```r theme_plain(jams) #> ┌──────────────────────┐ #> │ Type Price │ #> ├──────────────────────┤ #> │ Strawberry 1.90 │ #> │ Raspberry 2.10 │ #> │ Plum 1.80 │ #> └──────────────────────┘ #> #> Column names: Type, Price ``` -------------------------------- ### R: Example of Setting Bottom Border Style Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/border-styles.md Demonstrates how to set a 'dotted' bottom border for the first row of a huxtable. The example also shows how to apply a 'double' border to the entire table using a specific setter function. ```r jams <- set_all_borders(jams) bottom_border_style(jams)[1, ] <- "dotted" jams #> ┌────────────┬─────────┐ #> │ Type │ Price │ #> ├┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┤ #> │ Strawberry │ 1.90 │ #> ├────────────┼─────────┤ #> │ Raspberry │ 2.10 │ #> ├────────────┼─────────┤ #> │ Plum │ 1.80 │ #> └────────────┴─────────┘ #> #> Column names: Type, Price set_bottom_border_style(jams, "double") #> ┌────────────┬─────────┐ #> │ Type │ Price │ #> ├════════════┼═════════┤ #> │ Strawberry │ 1.90 │ #> ├════════════┼═════════┤ #> │ Raspberry │ 2.10 │ #> ├════════════┼═════════┤ #> │ Plum │ 1.80 │ #> └════════════┴═════════┘ #> #> Column names: Type, Price ``` -------------------------------- ### Set and Get Row Heights Example Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/row_height.md This example demonstrates how to set specific row heights for a huxtable using a numeric vector and then retrieve the set heights. Numeric values are treated as proportions. ```r row_height(jams) <- c(.4, .2, .2, .2) row_height(jams) ``` -------------------------------- ### Huxtable Initialization with All Options Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html A comprehensive example showing Huxtable initialized with data, custom columns, sorting, filtering, pagination, and event handling. ```javascript var table = new Huxtable(document.getElementById('my-table'), { data: [ { "id": 1, "name": "John Doe", "email": "john.doe@example.com" }, { "id": 2, "name": "Jane Smith", "email": "jane.smith@example.com" }, { "id": 3, "name": "Peter Jones", "email": "peter.jones@example.com" } ], columns: [ { label: 'Name', key: 'name' }, { label: 'Email Address', key: 'email' } ], sortable: true, filterable: true, pagination: { perPage: 5 } }); table.on('rowClick', function(event, row) { console.log('Row clicked:', row); }); ``` -------------------------------- ### Getting Closest Ancestor with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .closest() method retrieves the first ancestor element that matches a selector, starting from the current element and moving up the DOM tree. It includes the element itself. ```javascript S.fn.extend({ closest: function(e, t) { var n, r = 0, i = this.length, o = [], a = "string" != typeof e && S(e); if (!k.test(e)) for (; r < i; r++) for (n = this[r]; n && n !== t; n = n.parentNode) if (n.nodeType < 11 && (a ? -1 < a.index(n) : 1 === n.nodeType && S.find.matchesSelector(n, e))) { o.push(n); break } return this.pushStack(1 < o.length ? S.uniqueSort(o) : o) } ``` -------------------------------- ### Generate LaTeX from Matrix Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/quick-output.html This example shows how to create a LaTeX file from a matrix using the `quick_latex` function. This is useful for including tables in LaTeX documents. ```R if (FALSE) { # \dontrun{ m <- matrix(1:4, 2, 2) quick_latex(m, jams) } ``` -------------------------------- ### Set and get default huxtable properties Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/set_default_properties.md Use `set_default_properties` to change default properties and `get_default_properties` to retrieve them. The former returns previous values invisibly. This example demonstrates setting text color and border, creating a table, and then resetting defaults and checking a specific property. ```r old <- set_default_properties( text_color = "red", border = 0.4 ) hux(a = 1:2, b = 1:2) #> ┌─────────┬─────────┐ #> │ a │ b │ #> ├─────────┼─────────┤ #> │ 1 │ 1 │ #> ├─────────┼─────────┤ #> │ 2 │ 2 │ #> └─────────┴─────────┘ #> #> #> Column names: a, b set_default_properties(old) get_default_properties("bold") #> $bold #> [1] FALSE #> ``` -------------------------------- ### Initial Table Setup with Padding Source: https://github.com/hughjonesd/huxtable/blob/master/docs/articles/huxtable.md Sets up an initial huxtable from the iris dataset, groups by species, selects columns, and applies basic theme and padding. ```r iris_hux <- iris |> group_by(Species) |> select(Species, Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) |> slice(1:5) |> as_hux() |> theme_basic() |> set_tb_padding(2) iris_hux ``` -------------------------------- ### Create Table using Pipe Interface Source: https://github.com/hughjonesd/huxtable/blob/master/index.md This example demonstrates creating a table and applying styles using the pipe operator (%>%) for a more fluent syntax. It achieves the same styling as the direct manipulation method. ```r library(magrittr) ht <- hux( Employee = c("John Smith", "Jane Doe", "David Hugh-Jones"), Salary = c(50000, 50000, 40000) ) ht |> set_bold(1, everywhere) и> set_bottom_border(1, everywhere) и> set_align(everywhere, 2, "right") и> set_lr_padding(10) и> set_width(0.35) и> set_number_format(2) ``` -------------------------------- ### Install LaTeX Dependencies Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/report_latex_dependencies.md Installs or updates the LaTeX packages required by huxtable. It attempts to use `tinytex::tlmgr_install()` or `tlmgr install`. ```r install_latex_dependencies() ``` -------------------------------- ### Create a Simple Huxtable Source: https://github.com/hughjonesd/huxtable/blob/master/docs/index.md Demonstrates basic table creation with column alignment, padding, width, and number formatting. Use this for straightforward table generation. ```R ht <- hux( Employee = c("John Smith", "Jane Doe", "David Hugh-Jones"), Salary = c(50000, 50000, 40000), add_colnames = TRUE ) bold(ht)[1,] <- TRUE bottom_border(ht)[1,] <- 0.4 align(ht)[,2] <- "right" right_padding(ht) <- 10 left_padding(ht) <- 10 width(ht) <- 0.35 number_format(ht) <- 2 ht ``` -------------------------------- ### Get tabular environment Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/tabular_environment.md Get the current tabular environment setting for a huxtable. ```r tabular_environment(ht) ``` -------------------------------- ### Basic HTML Table with Huxtable Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html Demonstrates creating a simple HTML table using Huxtable. This is a foundational example for displaying tabular data. ```html Huxtable Example
``` -------------------------------- ### Bright Theme Example Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/themes.md Applies a bright theme with distinct borders and colors. Good for highlighting key information. ```r theme_bright(jams) #> ┌────────────┬─────────┐ #> │ Type │ Price │ #> ├────────────┼─────────┤ #> │ Strawberry │ 1.90 │ #> ├────────────┼─────────┤ #> │ Raspberry │ 2.10 │ #> ├────────────┼─────────┤ #> │ Plum │ 1.80 │ #> └────────────┴─────────┘ #> #> Column names: Type, Price ``` -------------------------------- ### Generate PDF from Matrix using Typst Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/quick-output.html This example shows how to generate a PDF directly from a matrix using Typst via the `quick_typst_pdf` function. This requires the `typst` command-line tool. ```R if (FALSE) { # \dontrun{ m <- matrix(1:4, 2, 2) quick_typst_pdf(m, jams) } ``` -------------------------------- ### Huxtable Initialization with Data and Columns Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html Initializes Huxtable with sample data and column definitions. This is a basic setup for rendering a table. ```javascript const data = [ { name: 'Alice', active: true, url: '#', date: new Date() }, { name: 'Bob', active: false, url: '#', date: new Date() } ]; const columns = [ { label: 'Name', property: 'name' }, { label: 'Active', property: 'active', renderer: (value) => value ? 'Yes' : 'No' }, { label: 'Link', property: 'url', renderer: (value, row) => `${row.name}` }, { label: 'Date', property: 'date', renderer: formatDate } ]; new Huxtable(document.getElementById('my-table'), data, columns); ``` -------------------------------- ### Get thickness of a brdr() object Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/brdr_thickness.html Demonstrates how to get the thickness of a brdr() object. This function is useful for inspecting border properties. ```r brdr_thickness(left_border(jams)) #> Type Price #> 1 0 0 #> 1.1 0 0 #> 2 0 0 #> 3 0 0 ``` ```r brdr_thickness(brdr(1, "solid", "red")) #> [1] 1 ``` -------------------------------- ### Create a Simple Huxtable Source: https://github.com/hughjonesd/huxtable/blob/master/docs/index.html Demonstrates basic table creation and styling using the hux() function and individual styling functions. Use this for straightforward table generation with custom formatting. ```R ht <- hux( Employee = c("John Smith", "Jane Doe", "David Hugh-Jones"), Salary = c(50000, 50000, 40000), add_colnames = TRUE ) bold(ht)[1,] <- TRUE bottom_border(ht)[1,] <- 0.4 align(ht)[,2] <- "right" right_padding(ht) <- 10 left_padding(ht) <- 10 width(ht) <- 0.35 number_format(ht) <- 2 ht ``` -------------------------------- ### Get and Set CSS Properties Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html Use the `.css()` method to get or set CSS properties for elements. When setting, you can pass a single property-value pair or an object of multiple properties. When getting, you can retrieve a single property's value or an object containing multiple properties. ```javascript S.extend({ cssHooks:{ opacity:{ get:function(e,t){ if(t){ var n=We(e,"opacity"); return""===n?"1":n } } }}, cssNumber:{ animationIterationCount:!0, columnCount:!0, fillOpacity:!0, flexGrow:!0, flexShrink:!0, fontWeight:!0, gridArea:!0, gridColumn:!0, gridColumnEnd:!0, gridColumnStart:!0, gridRow:!0, gridRowEnd:!0, gridRowStart:!0, lineHeight:!0, opacity:!0, order:!0, orphans:!0, widows:!0, zIndex:!0, zoom:!0 }, cssProps:{}, style:function(e,t,n,r){ if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){ var i,o,a,s=X(t), u=Xe.test(t), l=e.style; if(u||(t=ze(s)),a=S.cssHooks[t]||S.cssHooks[s]),void 0===n?a&&"get"in a&&void 0!==(i=a.get(e,!1,r))?i:l[t]{"string"===(o=typeof n)&&(i=te.exec(n))&&i[1]&&(n=se(e,t,i),o="number"),null!=n&&n==n&&("number"!==o||u||(n+=i&&i[3]||(S.cssNumber[s]? ``` ```javascript "":"px")),a&&"set"in a&&void 0===(n=a.set(e,n,r))||(u?l.setProperty(t,n):l[t]=n)) } }}, css:function(e,t,n,r){ var i,o,a,s=X(t); return Xe.test(t)||(t=ze(s)),(a=S.cssHooks[t]||S.cssHooks[s])&&"get"in a&&(i=a.get(e,!0,n)),void 0===i&&(i=We(e,t,r)),"normal"===i&&t in Ge&&(i=Ge[t]),""===n||n?(o=parseFloat(i),!0===n||isFinite(o)?o||0:i):i }}),S.each(["height","width"],function(e,u){ S.cssHooks[u]={ get:function(e,t,n){ if(t)return!Ue.test(S.css(e,"display"))||e.getClientRects().length&&e.getBoundingClientRect().width?Je(e,u,n):Me(e,Ve,function(){return Je(e,u,n)}) }, set:function(e,t,n){ var r,i=Re(e),o=!y.scrollboxSize()&&"absolute"===i.position,a=(o||n)&&"border-box"===S.css(e,"boxSizing",!1,i),s=n?Qe(e,u,n,a,i):0; return a&&o&&(s-=Math.ceil(e["offset"+u[0].toUpperCase()+u.slice(1)]-parseFloat(i[u])-Qe(e,u,"border",!1,i)-.5)),s&&(r=te.exec(t))&&"px"!==(r[3]||"px")&&(e.style[u]=t,t=S.css(e,u)),Ye(0,t,s) } } }),S.cssHooks.marginLeft=Fe(y.reliableMarginLeft,function(e,t){ if(t)return(parseFloat(We(e,"marginLeft"))||e.getBoundingClientRect().left-Me(e,{marginLeft:0},function(){return e.getBoundingClientRect().left}))+"px" }),S.each({margin:"",padding:"",border:"Width"},function(i,o){ S.cssHooks[i+o]={ expand:function(e){ for(var t=0,n={},r="string"==typeof e?e.split(" "):[e];t<4;t++)n[i+ne[t]+o]=r[t]||r[t-2]||r[0]; return n } }, "margin"!==i&&(S.cssHooks[i+o].set=Ye) }),S.fn.extend({ css:function(e,t){ return $(this,function(e,t,n){ var r,i,o={},a=0; if(Array.isArray(t)){ for(r=Re(e),i=t.length;a Type Price #> Strawberry 1.90 #> Raspberry 2.10 #> Plum 1.80 #> #> Column names: Type, Price ``` -------------------------------- ### Huxtable Initialization with Options Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html Initializes Huxtable with data, columns, and custom options. This example includes custom table class and pagination settings. ```javascript const data = [ { name: 'Alice', active: true, url: '#', date: new Date() }, { name: 'Bob', active: false, url: '#', date: new Date() } ]; const columns = [ { label: 'Name', property: 'name' }, { label: 'Active', property: 'active', renderer: (value) => value ? 'Yes' : 'No' }, { label: 'Link', property: 'url', renderer: (value, row) => `${row.name}` }, { label: 'Date', property: 'date', renderer: formatDate } ]; const options = { tableClass: 'my-custom-table-class', pagination: { pageSize: 10 } }; new Huxtable(document.getElementById('my-table'), data, columns, options); ``` -------------------------------- ### Getting Siblings Until a Condition with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .nextUntil() method gets all sibling elements after the current element until a specified sibling is reached. It stops traversal at that point. ```javascript S.each({ nextUntil: function(e, t, n) { return h(e, "nextSibling", n) } ``` -------------------------------- ### Get and Set Caption Position Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/caption_pos.md Use `caption_pos()` to get the current caption position and `caption_pos() <- value` or `set_caption_pos()` to set it. The default position is 'top'. ```r caption_pos(ht) caption_pos(ht) <- value set_caption_pos(ht, value) ``` -------------------------------- ### Quick PowerPoint Output Source: https://github.com/hughjonesd/huxtable/blob/master/docs/news/index.html Use `quick_pptx` for convenient generation of PowerPoint presentations directly from huxtable objects. This function is improved for better output. ```r quick_pptx(ht) ``` -------------------------------- ### Getting Preceding Siblings Until a Condition with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .prevUntil() method gets all sibling elements before the current element until a specified sibling is reached. It stops traversal at that point. ```javascript S.each({ prevUntil: function(e, t, n) { return h(e, "previousSibling", n) } ``` -------------------------------- ### Get and set caption width Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/caption_width.md Use `caption_width()` to get the current caption width and `caption_width() <- value` to set it. `set_caption_width()` is an alternative function for setting the width. ```r caption_width(ht) caption_width(ht) <- value set_caption_width(ht, value) ``` -------------------------------- ### Huxtable with Multiple Column Configurations Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html Shows how to define multiple column configurations, including labels, accessors, and custom rendering. ```javascript var table = new Huxtable("#myTable", { "data": [ {"firstName": "Alice", "lastName": "Smith", "years": 30}, {"firstName": "Bob", "lastName": "Jones", "years": 25} ], "columns": [ {"label": "Name", "accessor": "firstName"}, {"label": "Surname", "accessor": "lastName"}, { "label": "Age", "accessor": "years", "render": function(value, row) { return value + " years old"; } } ] }); ``` -------------------------------- ### Getting All Preceding Siblings with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .prevAll() method gets all sibling elements before the current element in the DOM tree. It's useful for selecting a range of preceding elements. ```javascript S.each({ prevAll: function(e) { return h(e, "previousSibling") } ``` -------------------------------- ### Getting All Following Siblings with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .nextAll() method gets all sibling elements after the current element in the DOM tree. It's useful for selecting a range of subsequent elements. ```javascript S.each({ nextAll: function(e) { return h(e, "nextSibling") } ``` -------------------------------- ### Example: Set Vertical Alignment to 'top' Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/valign.md Demonstrates setting the vertical alignment of all cells in a huxtable to 'top' and then retrieving the values to verify. ```r valign(jams) <- "top" valign(jams) #> Type Price #> 1 "top" "top" #> 1.1 "top" "top" #> 2 "top" "top" #> 3 "top" "top" ``` -------------------------------- ### Get and set table label Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/label.md Use `label(ht)` to get the current label of a huxtable and `label(ht) <- value` to set it. The `value` should be a string, or `NA` to reset. ```r label(ht) label(ht) <- value ``` -------------------------------- ### Get and Set Font Size Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/font_size.md Use `font_size()` to get the current font size of a huxtable or assign a new font size. Assigning `NA` resets to default. ```r font_size(ht) font_size(ht) <- value ``` ```r font_size(jams) <- 14 font_size(jams) #> Type Price #> 1 14 14 #> 1.1 14 14 #> 2 14 14 #> 3 14 14 ``` -------------------------------- ### Getting Siblings of an Element with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .siblings() method gets all sibling elements of each element in the set of matched elements, excluding the elements themselves. It's useful for selecting elements at the same level. ```javascript S.each({ siblings: function(e) { return T((e.parentNode || {}).firstChild, e) } ``` -------------------------------- ### Blue Theme Example Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/themes.md Applies a blue theme with distinct borders. Provides a visually appealing and modern aesthetic. ```r theme_blue(jams) #> ┌────────────┬─────────┐ #> │ Type │ Price │ #> ├────────────┼─────────┤ #> │ Strawberry │ 1.90 │ #> ├────────────┼─────────┤ #> │ Raspberry │ 2.10 │ #> ├────────────┼─────────┤ #> │ Plum │ 1.80 │ #> └────────────┴─────────┘ #> #> Column names: Type, Price ``` -------------------------------- ### Getting Ancestors Until a Condition with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .parentsUntil() method gets the direct and indirect ancestors of each element in the set of matched elements until a specified ancestor is reached. It stops traversal at that point. ```javascript S.each({ parentsUntil: function(e, t, n) { return h(e, "parentNode", n) } ``` -------------------------------- ### Create and Display a Flextable using Huxtable Source: https://github.com/hughjonesd/huxtable/blob/master/scripts/quarto-tester-2.md This snippet demonstrates how to use the huxtable package to create a table and then display it using the flextable function. It requires the huxtable and flextable libraries to be loaded. ```r library(huxtable) flextable::flextable(mtcars[1:2,1:2]) ``` -------------------------------- ### Getting Ancestor Elements with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .parents() method gets the direct and indirect ancestors of each element in the set of matched elements. Use it to traverse up the DOM tree multiple levels. ```javascript S.each({ parents: function(e) { return h(e, "parentNode") } ``` -------------------------------- ### Example of Setting Table Height Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/height.md Demonstrates how to set the height of a huxtable using the set_height() function with a proportional value. ```r set_height(jams, 0.4) #> Type Price #> Strawberry 1.90 #> Raspberry 2.10 #> Plum 1.80 #> #> Column names: Type, Price ``` -------------------------------- ### Print huxtable to screen Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/to_screen.html This example demonstrates how to format and print a huxtable to the console using print_screen. It applies bottom borders, bold text, and text color based on content. ```R bottom_border(jams)[1, 1:2] <- 1 bold(jams)[1, 1:2] <- TRUE jams <- map_text_color( jams, by_regex("berry" = "red") ) print_screen(jams) ``` -------------------------------- ### Getting Parent Elements with jQuery Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html The .parent() method gets the direct parent of each element in the set of matched elements. It's useful for navigating up the DOM tree one level. ```javascript S.each({ parent: function(e) { var t = e.parentNode; return t && 11 !== t.nodeType ? t : null } ``` -------------------------------- ### Example: Set Bottom Border Thickness Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/borders.md Demonstrates setting the bottom border thickness for the first row of a huxtable to 0.4. ```r bottom_border(jams)[1, ] <- 0.4 jams #> Type Price #> ──────────────────────── #> Strawberry 1.90 #> Raspberry 2.10 #> Plum 1.80 #> #> Column names: Type, Price ``` -------------------------------- ### Get or Set Header Rows Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/header_cols.md Use `header_rows(ht)` to get the logical vector indicating which rows are headers. Use `header_rows(ht) <- value` to set which rows are headers. ```r header_rows(ht) header_rows(ht) <- value ``` -------------------------------- ### Pagination with Huxtable Source: https://github.com/hughjonesd/huxtable/blob/master/docs/huxtable-html.html Demonstrates how to implement pagination for Huxtable to manage large datasets. This improves performance and user experience. ```javascript new Huxtable("#table-container", { data: data, columns: [ { label: "ID", accessor: "id" }, { label: "Name", accessor: "name" }, { label: "Age", accessor: "age" } ], pagination: { pageSize: 10 } }); ``` -------------------------------- ### Set default properties and create a huxtable Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/set_default_properties.html Sets default text color and border thickness, then creates a huxtable. The original default properties are captured and can be restored later. Note that `autoformat = TRUE` in `huxtable()` overrides some defaults. ```R old <- set_default_properties( text_color = "red", border = 0.4 ) hux(a = 1:2, b = 1:2) #> ┌─────────┬─────────┐ #> │ a │ b │ #> ├─────────┼─────────┤ #> │ 1 │ 1 │ #> ├─────────┼─────────┤ #> │ 2 │ 2 │ #> └─────────┴─────────┘ #> #> Column names: a, b set_default_properties(old) ``` -------------------------------- ### Get or Set Header Columns Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/header_cols.md Use `header_cols(ht)` to get the logical vector indicating which columns are headers. Use `header_cols(ht) <- value` to set which columns are headers. ```r header_cols(ht) header_cols(ht) <- value ``` -------------------------------- ### Get and Set Font Style Source: https://github.com/hughjonesd/huxtable/blob/master/docs/reference/font.md Use `font()` to get the current font style of a huxtable or assign a new font style. Assigning `NA` resets the font to its default. ```r font(ht) font(ht) <- value ``` ```r font(jams) <- "times" font(jams) ```