├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── Index.Rmd ├── Index.md ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── WIP │ ├── create_rmd_table.R │ ├── inserttable.Rmd │ └── inserttable.html ├── get_table_code.R └── insert_table.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── docs ├── 404.html ├── Index.html ├── LICENSE-text.html ├── LICENSE.html ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon.png ├── articles │ ├── index.html │ ├── inserttable.html │ └── inserttable_files │ │ └── figure-html │ │ ├── unnamed-chunk-1-1.png │ │ └── unnamed-chunk-1-2.png ├── authors.html ├── docsearch.css ├── docsearch.js ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── index.html ├── jquery.sticky-kit.min.js ├── link.svg ├── logo.png ├── man │ └── Figures │ │ ├── animation_1.gif │ │ ├── animation_2.gif │ │ ├── animation_3.gif │ │ └── animation_4.gif ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── figures │ │ ├── animation_1.gif │ │ ├── animation_2.gif │ │ ├── animation_3.gif │ │ ├── animation_4.gif │ │ ├── insert-table.svg │ │ └── logo.png │ ├── get_table_code.html │ ├── index.html │ └── insert_table.html ├── sitemap.txt └── sitemap.xml ├── insert_table.Rproj ├── inserttable.Rproj ├── inst ├── WORDLIST └── rstudio │ └── addins.dcf ├── man ├── figures │ ├── animation_1.gif │ ├── animation_2.gif │ ├── animation_3.gif │ ├── animation_4.gif │ ├── insert-table.svg │ └── logo.png ├── get_table_code.Rd └── insert_table.Rd ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── tests └── spelling.R └── vignettes └── .gitignore /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^inserttable\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^\.travis\.yml$ 5 | ^README\.Rmd$ 6 | ^_pkgdown\.yml$ 7 | ^docs$ 8 | ^R\WIP$ 9 | Index.Rmd 10 | .Rproj$ 11 | ^pkgdown$ 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | # Example code in package build process 8 | *-Ex.R 9 | # Output files from R CMD build 10 | /*.tar.gz 11 | # Output files from R CMD check 12 | /*.Rcheck/ 13 | # RStudio files 14 | .Rproj.user/ 15 | # produced vignettes 16 | vignettes/*.html 17 | vignettes/*.pdf 18 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 19 | .httr-oauth 20 | # knitr and R markdown default cache directories 21 | /*_cache/ 22 | /cache/ 23 | # Temporary files created by R markdown 24 | *.utf8.md 25 | *.knit.md 26 | .Rproj.user 27 | inst/doc 28 | R/WIP 29 | 30 | insert_table\.Rproj 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | cache: packages 5 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: inserttable 2 | Title: Automatically Add a Table to a RMarkdown Document 3 | Version: 0.4.0 4 | Authors@R: c(person("Lorenzo", "Busetto", email = "lbusett@gmail.com", role = c("aut", "cre"), 5 | comment = c(ORCID = '0000-0001-9634-6038'))) 6 | Description: Function and RStudio add-in allowing to quickly and automatically 7 | generate the code needed to render a table in a RMarkdown document using different 8 | formats (kable, DT and rhandsontable are currently implemented). 9 | License: GPL-3 10 | Imports: 11 | tibble, rstudioapi, shiny, miniUI, datapasta, assertthat, anytime, rhandsontable 12 | Suggests: 13 | testthat, 14 | knitr, 15 | rmarkdown, 16 | spelling 17 | ByteCompile: true 18 | Encoding: UTF-8 19 | LazyData: true 20 | RoxygenNote: 6.1.1 21 | VignetteBuilder: knitr 22 | URL: https://github.com/lbusett/insert_table 23 | BugReports: https://github.com/lbusett/insert_table/issues 24 | Language: en-US 25 | -------------------------------------------------------------------------------- /Index.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | ```{r setup, include = FALSE} 7 | knitr::opts_chunk$set( 8 | collapse = TRUE, 9 | comment = "#>", 10 | fig.path = "man/figures/README-", 11 | out.width = "100%" 12 | ) 13 | 14 | ``` 15 | # inserttable 16 | 17 | `inserttable` is an RStudio add-in facilitating insertion of nicely formatted 18 | tables in R markdown documents or plain R scripts. 19 | 20 | ## Installation 21 | 22 | You can install `inserttable` from [GitHub](https://github.com/lbusett/insert_table) 23 | with: 24 | 25 | ``` r 26 | # install.packages("devtools") 27 | devtools::install_github("lbusett/insert_table") 28 | ``` 29 | 30 | ## Usage 31 | 32 | Upon installing, `inserttable` registers a new RStudio Addin (__Insert Table__) 33 | that can be used to easily insert a table in a `Rmd` document. To use it, open a 34 | `Rmd` document and, with the cursor within a `r` chunk and select "Addins --> Insert Table". 35 | 36 | These are the two main __use modes__: 37 | 38 | 39 | ### Launch the addin with the cursor on a empty line 40 | 41 | In this case, a GUI will open allowing you to __select the desired output format__ ( 42 | `kableExtra`, `DT` and `rhandsontable` are currently implemented), and to __edit the 43 | content of the table__. After clicking __Done__ the Addin will add in the file 44 | the code needed to generate the table in a nice `tribble` format (thanks 45 | to Miles McBain's [`datapasta`](https://github.com/milesmcbain/datapasta) package!) 46 | to allow easier additional editing, and also the code needed to render it with the selected 47 | output format using some default options, as can be seen below: 48 | 49 | __IMPORTANT NOTE:__ Not all output formats play well with knitting to PDF or Word!. 50 | `kable` works everywhere, while `DT` and `rhandsontable` work out of the box only 51 | if knitting to html. You can make them work on PDF and Word by adding 52 | `always_allow_html: yes` in the yaml header of the Rmd, and installing __phantomjs__ using: 53 | `webshot::install_phantomjs()` (results are not that good, though). 54 | 55 | 56 | ![](man/figures/animation_1.gif) 57 | 58 | 59 | A useful feature is that, for larger tables, you can also __cut and paste content from a spreadsheet__ : 60 | 61 | ![](man/figures/animation_2.gif) 62 | 63 | 64 | Obviously, rendering of the table can be tweaked further by changing/adding arguments of the rendering functions in the automatically generated code. 65 | 66 | ### Launch the addin while selecting the name of a variable 67 | 68 | In this case, the GUI allows you to select __only the desired output format__ ( 69 | it is assumed that the variable you select corresponds to a `data frame` or similar 70 | object containing the data you wish to show as table). After clicking __Done__ 71 | the Addin will add in the `Rmd` document the code needed to render the selected variable as a table with the selected output format. The code will be added at the first empty line below that containing the name of the selected variable. 72 | 73 | 74 | ![](man/figures/animation_3.gif) 75 | 76 | 77 | __IMPORTANT NOTE__: `inserttable` will make no effort to guarantee that the 78 | variable you select is a `data.frame`. It is up to you to select a meaningful 79 | variable! 80 | 81 | 82 | ## Usage from the console 83 | 84 | You can also use (part of) `inserttable` functionality from the console by calling 85 | function `insert_table()`. 86 | 87 | ```{r eval=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE} 88 | 89 | > insert_table(tbl_name = "table_1", nrows = 4, ncols = 4, tbl_format = "DT") 90 | 91 | ``` 92 | 93 | The function will return __to the console__ the code needed to create a empty 94 | table of the specified dimensions and render it with the selected format: 95 | 96 | ![](man/figures/animation_4.gif) 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Index.md: -------------------------------------------------------------------------------- 1 | 2 | # inserttable 3 | 4 | `inserttable` is an RStudio add-in facilitating insertion of nicely 5 | formatted tables in R markdown documents or plain R scripts. 6 | 7 | ## Installation 8 | 9 | You can install `inserttable` from 10 | [GitHub](https://github.com/lbusett/insert_table) with: 11 | 12 | ``` r 13 | # install.packages("devtools") 14 | devtools::install_github("lbusett/insert_table") 15 | ``` 16 | 17 | ## Usage 18 | 19 | Upon installing, `inserttable` registers a new RStudio Addin (**Insert 20 | Table**) that can be used to easily insert a table in a `Rmd` document. 21 | To use it, open a `Rmd` document and, with the cursor within a `r` chunk 22 | and select “Addins –\> Insert Table”. 23 | 24 | These are the two main **use modes**: 25 | 26 | ### Launch the addin with the cursor on a empty line 27 | 28 | In this case, a GUI will open allowing you to **select the desired 29 | output format** ( `kableExtra`, `DT` and `rhandsontable` are currently 30 | implemented), and to **edit the content of the table**. After clicking 31 | **Done** the Addin will add in the file the code needed to generate the 32 | table in a nice `tribble` format (thanks to Miles McBain’s 33 | [`datapasta`](https://github.com/milesmcbain/datapasta) package\!) to 34 | allow easier additional editing, and also the code needed to render it 35 | with the selected output format using some default options, as can be 36 | seen below: 37 | 38 | **IMPORTANT NOTE:** Not all output formats play well with knitting to 39 | PDF or Word\!. `kable` works everywhere, while `DT` and `rhandsontable` 40 | work out of the box only if knitting to html. You can make them work on 41 | PDF and Word by adding `always_allow_html: yes` in the yaml header of 42 | the Rmd, and installing **phantomjs** using: 43 | `webshot::install_phantomjs()` (results are not that good, though). 44 | 45 | ![](man/figures/animation_1.gif) 46 | 47 | A useful feature is that, for larger tables, you can also **cut and 48 | paste content from a spreadsheet** : 49 | 50 | ![](man/figures/animation_2.gif) 51 | 52 | Obviously, rendering of the table can be tweaked further by 53 | changing/adding arguments of the rendering functions in the 54 | automatically generated code. 55 | 56 | ### Launch the addin while selecting the name of a variable 57 | 58 | In this case, the GUI allows you to select **only the desired output 59 | format** ( it is assumed that the variable you select corresponds to a 60 | `data frame` or similar object containing the data you wish to show as 61 | table). After clicking **Done** the Addin will add in the `Rmd` document 62 | the code needed to render the selected variable as a table with the 63 | selected output format. The code will be added at the first empty line 64 | below that containing the name of the selected variable. 65 | 66 | ![](man/figures/animation_3.gif) 67 | 68 | **IMPORTANT NOTE**: `inserttable` will make no effort to guarantee that 69 | the variable you select is a `data.frame`. It is up to you to select a 70 | meaningful variable\! 71 | 72 | ## Usage from the console 73 | 74 | You can also use (part of) `inserttable` functionality from the console 75 | by calling function `insert_table()`. 76 | 77 | ``` r 78 | 79 | > insert_table(tbl_name = "table_1", nrows = 4, ncols = 4, tbl_format = "DT") 80 | ``` 81 | 82 | The function will return **to the console** the code needed to create a 83 | empty table of the specified dimensions and render it with the selected 84 | format: 85 | 86 | ![](man/figures/animation_4.gif) 87 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU General Public License 2 | ========================== 3 | 4 | _Version 3, 29 June 2007_ 5 | _Copyright © 2007 Free Software Foundation, Inc. <>_ 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license 8 | document, but changing it is not allowed. 9 | 10 | ## Preamble 11 | 12 | The GNU General Public License is a free, copyleft license for software and other 13 | kinds of works. 14 | 15 | The licenses for most software and other practical works are designed to take away 16 | your freedom to share and change the works. By contrast, the GNU General Public 17 | License is intended to guarantee your freedom to share and change all versions of a 18 | program--to make sure it remains free software for all its users. We, the Free 19 | Software Foundation, use the GNU General Public License for most of our software; it 20 | applies also to any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not price. Our General 24 | Public Licenses are designed to make sure that you have the freedom to distribute 25 | copies of free software (and charge for them if you wish), that you receive source 26 | code or can get it if you want it, that you can change the software or use pieces of 27 | it in new free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you these rights or 30 | asking you to surrender the rights. Therefore, you have certain responsibilities if 31 | you distribute copies of the software, or if you modify it: responsibilities to 32 | respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether gratis or for a fee, 35 | you must pass on to the recipients the same freedoms that you received. You must make 36 | sure that they, too, receive or can get the source code. And you must show them these 37 | terms so they know their rights. 38 | 39 | Developers that use the GNU GPL protect your rights with two steps: **(1)** assert 40 | copyright on the software, and **(2)** offer you this License giving you legal permission 41 | to copy, distribute and/or modify it. 42 | 43 | For the developers' and authors' protection, the GPL clearly explains that there is 44 | no warranty for this free software. For both users' and authors' sake, the GPL 45 | requires that modified versions be marked as changed, so that their problems will not 46 | be attributed erroneously to authors of previous versions. 47 | 48 | Some devices are designed to deny users access to install or run modified versions of 49 | the software inside them, although the manufacturer can do so. This is fundamentally 50 | incompatible with the aim of protecting users' freedom to change the software. The 51 | systematic pattern of such abuse occurs in the area of products for individuals to 52 | use, which is precisely where it is most unacceptable. Therefore, we have designed 53 | this version of the GPL to prohibit the practice for those products. If such problems 54 | arise substantially in other domains, we stand ready to extend this provision to 55 | those domains in future versions of the GPL, as needed to protect the freedom of 56 | users. 57 | 58 | Finally, every program is threatened constantly by software patents. States should 59 | not allow patents to restrict development and use of software on general-purpose 60 | computers, but in those that do, we wish to avoid the special danger that patents 61 | applied to a free program could make it effectively proprietary. To prevent this, the 62 | GPL assures that patents cannot be used to render the program non-free. 63 | 64 | The precise terms and conditions for copying, distribution and modification follow. 65 | 66 | ## TERMS AND CONDITIONS 67 | 68 | ### 0. Definitions 69 | 70 | “This License” refers to version 3 of the GNU General Public License. 71 | 72 | “Copyright” also means copyright-like laws that apply to other kinds of 73 | works, such as semiconductor masks. 74 | 75 | “The Program” refers to any copyrightable work licensed under this 76 | License. Each licensee is addressed as “you”. “Licensees” and 77 | “recipients” may be individuals or organizations. 78 | 79 | To “modify” a work means to copy from or adapt all or part of the work in 80 | a fashion requiring copyright permission, other than the making of an exact copy. The 81 | resulting work is called a “modified version” of the earlier work or a 82 | work “based on” the earlier work. 83 | 84 | A “covered work” means either the unmodified Program or a work based on 85 | the Program. 86 | 87 | To “propagate” a work means to do anything with it that, without 88 | permission, would make you directly or secondarily liable for infringement under 89 | applicable copyright law, except executing it on a computer or modifying a private 90 | copy. Propagation includes copying, distribution (with or without modification), 91 | making available to the public, and in some countries other activities as well. 92 | 93 | To “convey” a work means any kind of propagation that enables other 94 | parties to make or receive copies. Mere interaction with a user through a computer 95 | network, with no transfer of a copy, is not conveying. 96 | 97 | An interactive user interface displays “Appropriate Legal Notices” to the 98 | extent that it includes a convenient and prominently visible feature that **(1)** 99 | displays an appropriate copyright notice, and **(2)** tells the user that there is no 100 | warranty for the work (except to the extent that warranties are provided), that 101 | licensees may convey the work under this License, and how to view a copy of this 102 | License. If the interface presents a list of user commands or options, such as a 103 | menu, a prominent item in the list meets this criterion. 104 | 105 | ### 1. Source Code 106 | 107 | The “source code” for a work means the preferred form of the work for 108 | making modifications to it. “Object code” means any non-source form of a 109 | work. 110 | 111 | A “Standard Interface” means an interface that either is an official 112 | standard defined by a recognized standards body, or, in the case of interfaces 113 | specified for a particular programming language, one that is widely used among 114 | developers working in that language. 115 | 116 | The “System Libraries” of an executable work include anything, other than 117 | the work as a whole, that **(a)** is included in the normal form of packaging a Major 118 | Component, but which is not part of that Major Component, and **(b)** serves only to 119 | enable use of the work with that Major Component, or to implement a Standard 120 | Interface for which an implementation is available to the public in source code form. 121 | A “Major Component”, in this context, means a major essential component 122 | (kernel, window system, and so on) of the specific operating system (if any) on which 123 | the executable work runs, or a compiler used to produce the work, or an object code 124 | interpreter used to run it. 125 | 126 | The “Corresponding Source” for a work in object code form means all the 127 | source code needed to generate, install, and (for an executable work) run the object 128 | code and to modify the work, including scripts to control those activities. However, 129 | it does not include the work's System Libraries, or general-purpose tools or 130 | generally available free programs which are used unmodified in performing those 131 | activities but which are not part of the work. For example, Corresponding Source 132 | includes interface definition files associated with source files for the work, and 133 | the source code for shared libraries and dynamically linked subprograms that the work 134 | is specifically designed to require, such as by intimate data communication or 135 | control flow between those subprograms and other parts of the work. 136 | 137 | The Corresponding Source need not include anything that users can regenerate 138 | automatically from other parts of the Corresponding Source. 139 | 140 | The Corresponding Source for a work in source code form is that same work. 141 | 142 | ### 2. Basic Permissions 143 | 144 | All rights granted under this License are granted for the term of copyright on the 145 | Program, and are irrevocable provided the stated conditions are met. This License 146 | explicitly affirms your unlimited permission to run the unmodified Program. The 147 | output from running a covered work is covered by this License only if the output, 148 | given its content, constitutes a covered work. This License acknowledges your rights 149 | of fair use or other equivalent, as provided by copyright law. 150 | 151 | You may make, run and propagate covered works that you do not convey, without 152 | conditions so long as your license otherwise remains in force. You may convey covered 153 | works to others for the sole purpose of having them make modifications exclusively 154 | for you, or provide you with facilities for running those works, provided that you 155 | comply with the terms of this License in conveying all material for which you do not 156 | control copyright. Those thus making or running the covered works for you must do so 157 | exclusively on your behalf, under your direction and control, on terms that prohibit 158 | them from making any copies of your copyrighted material outside their relationship 159 | with you. 160 | 161 | Conveying under any other circumstances is permitted solely under the conditions 162 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 163 | 164 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law 165 | 166 | No covered work shall be deemed part of an effective technological measure under any 167 | applicable law fulfilling obligations under article 11 of the WIPO copyright treaty 168 | adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention 169 | of such measures. 170 | 171 | When you convey a covered work, you waive any legal power to forbid circumvention of 172 | technological measures to the extent such circumvention is effected by exercising 173 | rights under this License with respect to the covered work, and you disclaim any 174 | intention to limit operation or modification of the work as a means of enforcing, 175 | against the work's users, your or third parties' legal rights to forbid circumvention 176 | of technological measures. 177 | 178 | ### 4. Conveying Verbatim Copies 179 | 180 | You may convey verbatim copies of the Program's source code as you receive it, in any 181 | medium, provided that you conspicuously and appropriately publish on each copy an 182 | appropriate copyright notice; keep intact all notices stating that this License and 183 | any non-permissive terms added in accord with section 7 apply to the code; keep 184 | intact all notices of the absence of any warranty; and give all recipients a copy of 185 | this License along with the Program. 186 | 187 | You may charge any price or no price for each copy that you convey, and you may offer 188 | support or warranty protection for a fee. 189 | 190 | ### 5. Conveying Modified Source Versions 191 | 192 | You may convey a work based on the Program, or the modifications to produce it from 193 | the Program, in the form of source code under the terms of section 4, provided that 194 | you also meet all of these conditions: 195 | 196 | * **a)** The work must carry prominent notices stating that you modified it, and giving a 197 | relevant date. 198 | * **b)** The work must carry prominent notices stating that it is released under this 199 | License and any conditions added under section 7. This requirement modifies the 200 | requirement in section 4 to “keep intact all notices”. 201 | * **c)** You must license the entire work, as a whole, under this License to anyone who 202 | comes into possession of a copy. This License will therefore apply, along with any 203 | applicable section 7 additional terms, to the whole of the work, and all its parts, 204 | regardless of how they are packaged. This License gives no permission to license the 205 | work in any other way, but it does not invalidate such permission if you have 206 | separately received it. 207 | * **d)** If the work has interactive user interfaces, each must display Appropriate Legal 208 | Notices; however, if the Program has interactive interfaces that do not display 209 | Appropriate Legal Notices, your work need not make them do so. 210 | 211 | A compilation of a covered work with other separate and independent works, which are 212 | not by their nature extensions of the covered work, and which are not combined with 213 | it such as to form a larger program, in or on a volume of a storage or distribution 214 | medium, is called an “aggregate” if the compilation and its resulting 215 | copyright are not used to limit the access or legal rights of the compilation's users 216 | beyond what the individual works permit. Inclusion of a covered work in an aggregate 217 | does not cause this License to apply to the other parts of the aggregate. 218 | 219 | ### 6. Conveying Non-Source Forms 220 | 221 | You may convey a covered work in object code form under the terms of sections 4 and 222 | 5, provided that you also convey the machine-readable Corresponding Source under the 223 | terms of this License, in one of these ways: 224 | 225 | * **a)** Convey the object code in, or embodied in, a physical product (including a 226 | physical distribution medium), accompanied by the Corresponding Source fixed on a 227 | durable physical medium customarily used for software interchange. 228 | * **b)** Convey the object code in, or embodied in, a physical product (including a 229 | physical distribution medium), accompanied by a written offer, valid for at least 230 | three years and valid for as long as you offer spare parts or customer support for 231 | that product model, to give anyone who possesses the object code either **(1)** a copy of 232 | the Corresponding Source for all the software in the product that is covered by this 233 | License, on a durable physical medium customarily used for software interchange, for 234 | a price no more than your reasonable cost of physically performing this conveying of 235 | source, or **(2)** access to copy the Corresponding Source from a network server at no 236 | charge. 237 | * **c)** Convey individual copies of the object code with a copy of the written offer to 238 | provide the Corresponding Source. This alternative is allowed only occasionally and 239 | noncommercially, and only if you received the object code with such an offer, in 240 | accord with subsection 6b. 241 | * **d)** Convey the object code by offering access from a designated place (gratis or for 242 | a charge), and offer equivalent access to the Corresponding Source in the same way 243 | through the same place at no further charge. You need not require recipients to copy 244 | the Corresponding Source along with the object code. If the place to copy the object 245 | code is a network server, the Corresponding Source may be on a different server 246 | (operated by you or a third party) that supports equivalent copying facilities, 247 | provided you maintain clear directions next to the object code saying where to find 248 | the Corresponding Source. Regardless of what server hosts the Corresponding Source, 249 | you remain obligated to ensure that it is available for as long as needed to satisfy 250 | these requirements. 251 | * **e)** Convey the object code using peer-to-peer transmission, provided you inform 252 | other peers where the object code and Corresponding Source of the work are being 253 | offered to the general public at no charge under subsection 6d. 254 | 255 | A separable portion of the object code, whose source code is excluded from the 256 | Corresponding Source as a System Library, need not be included in conveying the 257 | object code work. 258 | 259 | A “User Product” is either **(1)** a “consumer product”, which 260 | means any tangible personal property which is normally used for personal, family, or 261 | household purposes, or **(2)** anything designed or sold for incorporation into a 262 | dwelling. In determining whether a product is a consumer product, doubtful cases 263 | shall be resolved in favor of coverage. For a particular product received by a 264 | particular user, “normally used” refers to a typical or common use of 265 | that class of product, regardless of the status of the particular user or of the way 266 | in which the particular user actually uses, or expects or is expected to use, the 267 | product. A product is a consumer product regardless of whether the product has 268 | substantial commercial, industrial or non-consumer uses, unless such uses represent 269 | the only significant mode of use of the product. 270 | 271 | “Installation Information” for a User Product means any methods, 272 | procedures, authorization keys, or other information required to install and execute 273 | modified versions of a covered work in that User Product from a modified version of 274 | its Corresponding Source. The information must suffice to ensure that the continued 275 | functioning of the modified object code is in no case prevented or interfered with 276 | solely because modification has been made. 277 | 278 | If you convey an object code work under this section in, or with, or specifically for 279 | use in, a User Product, and the conveying occurs as part of a transaction in which 280 | the right of possession and use of the User Product is transferred to the recipient 281 | in perpetuity or for a fixed term (regardless of how the transaction is 282 | characterized), the Corresponding Source conveyed under this section must be 283 | accompanied by the Installation Information. But this requirement does not apply if 284 | neither you nor any third party retains the ability to install modified object code 285 | on the User Product (for example, the work has been installed in ROM). 286 | 287 | The requirement to provide Installation Information does not include a requirement to 288 | continue to provide support service, warranty, or updates for a work that has been 289 | modified or installed by the recipient, or for the User Product in which it has been 290 | modified or installed. Access to a network may be denied when the modification itself 291 | materially and adversely affects the operation of the network or violates the rules 292 | and protocols for communication across the network. 293 | 294 | Corresponding Source conveyed, and Installation Information provided, in accord with 295 | this section must be in a format that is publicly documented (and with an 296 | implementation available to the public in source code form), and must require no 297 | special password or key for unpacking, reading or copying. 298 | 299 | ### 7. Additional Terms 300 | 301 | “Additional permissions” are terms that supplement the terms of this 302 | License by making exceptions from one or more of its conditions. Additional 303 | permissions that are applicable to the entire Program shall be treated as though they 304 | were included in this License, to the extent that they are valid under applicable 305 | law. If additional permissions apply only to part of the Program, that part may be 306 | used separately under those permissions, but the entire Program remains governed by 307 | this License without regard to the additional permissions. 308 | 309 | When you convey a copy of a covered work, you may at your option remove any 310 | additional permissions from that copy, or from any part of it. (Additional 311 | permissions may be written to require their own removal in certain cases when you 312 | modify the work.) You may place additional permissions on material, added by you to a 313 | covered work, for which you have or can give appropriate copyright permission. 314 | 315 | Notwithstanding any other provision of this License, for material you add to a 316 | covered work, you may (if authorized by the copyright holders of that material) 317 | supplement the terms of this License with terms: 318 | 319 | * **a)** Disclaiming warranty or limiting liability differently from the terms of 320 | sections 15 and 16 of this License; or 321 | * **b)** Requiring preservation of specified reasonable legal notices or author 322 | attributions in that material or in the Appropriate Legal Notices displayed by works 323 | containing it; or 324 | * **c)** Prohibiting misrepresentation of the origin of that material, or requiring that 325 | modified versions of such material be marked in reasonable ways as different from the 326 | original version; or 327 | * **d)** Limiting the use for publicity purposes of names of licensors or authors of the 328 | material; or 329 | * **e)** Declining to grant rights under trademark law for use of some trade names, 330 | trademarks, or service marks; or 331 | * **f)** Requiring indemnification of licensors and authors of that material by anyone 332 | who conveys the material (or modified versions of it) with contractual assumptions of 333 | liability to the recipient, for any liability that these contractual assumptions 334 | directly impose on those licensors and authors. 335 | 336 | All other non-permissive additional terms are considered “further 337 | restrictions” within the meaning of section 10. If the Program as you received 338 | it, or any part of it, contains a notice stating that it is governed by this License 339 | along with a term that is a further restriction, you may remove that term. If a 340 | license document contains a further restriction but permits relicensing or conveying 341 | under this License, you may add to a covered work material governed by the terms of 342 | that license document, provided that the further restriction does not survive such 343 | relicensing or conveying. 344 | 345 | If you add terms to a covered work in accord with this section, you must place, in 346 | the relevant source files, a statement of the additional terms that apply to those 347 | files, or a notice indicating where to find the applicable terms. 348 | 349 | Additional terms, permissive or non-permissive, may be stated in the form of a 350 | separately written license, or stated as exceptions; the above requirements apply 351 | either way. 352 | 353 | ### 8. Termination 354 | 355 | You may not propagate or modify a covered work except as expressly provided under 356 | this License. Any attempt otherwise to propagate or modify it is void, and will 357 | automatically terminate your rights under this License (including any patent licenses 358 | granted under the third paragraph of section 11). 359 | 360 | However, if you cease all violation of this License, then your license from a 361 | particular copyright holder is reinstated **(a)** provisionally, unless and until the 362 | copyright holder explicitly and finally terminates your license, and **(b)** permanently, 363 | if the copyright holder fails to notify you of the violation by some reasonable means 364 | prior to 60 days after the cessation. 365 | 366 | Moreover, your license from a particular copyright holder is reinstated permanently 367 | if the copyright holder notifies you of the violation by some reasonable means, this 368 | is the first time you have received notice of violation of this License (for any 369 | work) from that copyright holder, and you cure the violation prior to 30 days after 370 | your receipt of the notice. 371 | 372 | Termination of your rights under this section does not terminate the licenses of 373 | parties who have received copies or rights from you under this License. If your 374 | rights have been terminated and not permanently reinstated, you do not qualify to 375 | receive new licenses for the same material under section 10. 376 | 377 | ### 9. Acceptance Not Required for Having Copies 378 | 379 | You are not required to accept this License in order to receive or run a copy of the 380 | Program. Ancillary propagation of a covered work occurring solely as a consequence of 381 | using peer-to-peer transmission to receive a copy likewise does not require 382 | acceptance. However, nothing other than this License grants you permission to 383 | propagate or modify any covered work. These actions infringe copyright if you do not 384 | accept this License. Therefore, by modifying or propagating a covered work, you 385 | indicate your acceptance of this License to do so. 386 | 387 | ### 10. Automatic Licensing of Downstream Recipients 388 | 389 | Each time you convey a covered work, the recipient automatically receives a license 390 | from the original licensors, to run, modify and propagate that work, subject to this 391 | License. You are not responsible for enforcing compliance by third parties with this 392 | License. 393 | 394 | An “entity transaction” is a transaction transferring control of an 395 | organization, or substantially all assets of one, or subdividing an organization, or 396 | merging organizations. If propagation of a covered work results from an entity 397 | transaction, each party to that transaction who receives a copy of the work also 398 | receives whatever licenses to the work the party's predecessor in interest had or 399 | could give under the previous paragraph, plus a right to possession of the 400 | Corresponding Source of the work from the predecessor in interest, if the predecessor 401 | has it or can get it with reasonable efforts. 402 | 403 | You may not impose any further restrictions on the exercise of the rights granted or 404 | affirmed under this License. For example, you may not impose a license fee, royalty, 405 | or other charge for exercise of rights granted under this License, and you may not 406 | initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging 407 | that any patent claim is infringed by making, using, selling, offering for sale, or 408 | importing the Program or any portion of it. 409 | 410 | ### 11. Patents 411 | 412 | A “contributor” is a copyright holder who authorizes use under this 413 | License of the Program or a work on which the Program is based. The work thus 414 | licensed is called the contributor's “contributor version”. 415 | 416 | A contributor's “essential patent claims” are all patent claims owned or 417 | controlled by the contributor, whether already acquired or hereafter acquired, that 418 | would be infringed by some manner, permitted by this License, of making, using, or 419 | selling its contributor version, but do not include claims that would be infringed 420 | only as a consequence of further modification of the contributor version. For 421 | purposes of this definition, “control” includes the right to grant patent 422 | sublicenses in a manner consistent with the requirements of this License. 423 | 424 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license 425 | under the contributor's essential patent claims, to make, use, sell, offer for sale, 426 | import and otherwise run, modify and propagate the contents of its contributor 427 | version. 428 | 429 | In the following three paragraphs, a “patent license” is any express 430 | agreement or commitment, however denominated, not to enforce a patent (such as an 431 | express permission to practice a patent or covenant not to sue for patent 432 | infringement). To “grant” such a patent license to a party means to make 433 | such an agreement or commitment not to enforce a patent against the party. 434 | 435 | If you convey a covered work, knowingly relying on a patent license, and the 436 | Corresponding Source of the work is not available for anyone to copy, free of charge 437 | and under the terms of this License, through a publicly available network server or 438 | other readily accessible means, then you must either **(1)** cause the Corresponding 439 | Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the 440 | patent license for this particular work, or **(3)** arrange, in a manner consistent with 441 | the requirements of this License, to extend the patent license to downstream 442 | recipients. “Knowingly relying” means you have actual knowledge that, but 443 | for the patent license, your conveying the covered work in a country, or your 444 | recipient's use of the covered work in a country, would infringe one or more 445 | identifiable patents in that country that you have reason to believe are valid. 446 | 447 | If, pursuant to or in connection with a single transaction or arrangement, you 448 | convey, or propagate by procuring conveyance of, a covered work, and grant a patent 449 | license to some of the parties receiving the covered work authorizing them to use, 450 | propagate, modify or convey a specific copy of the covered work, then the patent 451 | license you grant is automatically extended to all recipients of the covered work and 452 | works based on it. 453 | 454 | A patent license is “discriminatory” if it does not include within the 455 | scope of its coverage, prohibits the exercise of, or is conditioned on the 456 | non-exercise of one or more of the rights that are specifically granted under this 457 | License. You may not convey a covered work if you are a party to an arrangement with 458 | a third party that is in the business of distributing software, under which you make 459 | payment to the third party based on the extent of your activity of conveying the 460 | work, and under which the third party grants, to any of the parties who would receive 461 | the covered work from you, a discriminatory patent license **(a)** in connection with 462 | copies of the covered work conveyed by you (or copies made from those copies), or **(b)** 463 | primarily for and in connection with specific products or compilations that contain 464 | the covered work, unless you entered into that arrangement, or that patent license 465 | was granted, prior to 28 March 2007. 466 | 467 | Nothing in this License shall be construed as excluding or limiting any implied 468 | license or other defenses to infringement that may otherwise be available to you 469 | under applicable patent law. 470 | 471 | ### 12. No Surrender of Others' Freedom 472 | 473 | If conditions are imposed on you (whether by court order, agreement or otherwise) 474 | that contradict the conditions of this License, they do not excuse you from the 475 | conditions of this License. If you cannot convey a covered work so as to satisfy 476 | simultaneously your obligations under this License and any other pertinent 477 | obligations, then as a consequence you may not convey it at all. For example, if you 478 | agree to terms that obligate you to collect a royalty for further conveying from 479 | those to whom you convey the Program, the only way you could satisfy both those terms 480 | and this License would be to refrain entirely from conveying the Program. 481 | 482 | ### 13. Use with the GNU Affero General Public License 483 | 484 | Notwithstanding any other provision of this License, you have permission to link or 485 | combine any covered work with a work licensed under version 3 of the GNU Affero 486 | General Public License into a single combined work, and to convey the resulting work. 487 | The terms of this License will continue to apply to the part which is the covered 488 | work, but the special requirements of the GNU Affero General Public License, section 489 | 13, concerning interaction through a network will apply to the combination as such. 490 | 491 | ### 14. Revised Versions of this License 492 | 493 | The Free Software Foundation may publish revised and/or new versions of the GNU 494 | General Public License from time to time. Such new versions will be similar in spirit 495 | to the present version, but may differ in detail to address new problems or concerns. 496 | 497 | Each version is given a distinguishing version number. If the Program specifies that 498 | a certain numbered version of the GNU General Public License “or any later 499 | version” applies to it, you have the option of following the terms and 500 | conditions either of that numbered version or of any later version published by the 501 | Free Software Foundation. If the Program does not specify a version number of the GNU 502 | General Public License, you may choose any version ever published by the Free 503 | Software Foundation. 504 | 505 | If the Program specifies that a proxy can decide which future versions of the GNU 506 | General Public License can be used, that proxy's public statement of acceptance of a 507 | version permanently authorizes you to choose that version for the Program. 508 | 509 | Later license versions may give you additional or different permissions. However, no 510 | additional obligations are imposed on any author or copyright holder as a result of 511 | your choosing to follow a later version. 512 | 513 | ### 15. Disclaimer of Warranty 514 | 515 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 516 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 517 | PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER 518 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 519 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE 520 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 521 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 522 | 523 | ### 16. Limitation of Liability 524 | 525 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 526 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 527 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 528 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 529 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE 530 | OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE 531 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 532 | POSSIBILITY OF SUCH DAMAGES. 533 | 534 | ### 17. Interpretation of Sections 15 and 16 535 | 536 | If the disclaimer of warranty and limitation of liability provided above cannot be 537 | given local legal effect according to their terms, reviewing courts shall apply local 538 | law that most closely approximates an absolute waiver of all civil liability in 539 | connection with the Program, unless a warranty or assumption of liability accompanies 540 | a copy of the Program in return for a fee. 541 | 542 | _END OF TERMS AND CONDITIONS_ 543 | 544 | ## How to Apply These Terms to Your New Programs 545 | 546 | If you develop a new program, and you want it to be of the greatest possible use to 547 | the public, the best way to achieve this is to make it free software which everyone 548 | can redistribute and change under these terms. 549 | 550 | To do so, attach the following notices to the program. It is safest to attach them 551 | to the start of each source file to most effectively state the exclusion of warranty; 552 | and each file should have at least the “copyright” line and a pointer to 553 | where the full notice is found. 554 | 555 | 556 | Copyright (C) 2019 Lorenzo Busetto 557 | 558 | This program is free software: you can redistribute it and/or modify 559 | it under the terms of the GNU General Public License as published by 560 | the Free Software Foundation, either version 3 of the License, or 561 | (at your option) any later version. 562 | 563 | This program is distributed in the hope that it will be useful, 564 | but WITHOUT ANY WARRANTY; without even the implied warranty of 565 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 566 | GNU General Public License for more details. 567 | 568 | You should have received a copy of the GNU General Public License 569 | along with this program. If not, see . 570 | 571 | Also add information on how to contact you by electronic and paper mail. 572 | 573 | If the program does terminal interaction, make it output a short notice like this 574 | when it starts in an interactive mode: 575 | 576 | inserttable Copyright (C) 2019 Lorenzo Busetto 577 | This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. 578 | This is free software, and you are welcome to redistribute it 579 | under certain conditions; type 'show c' for details. 580 | 581 | The hypothetical commands `show w` and `show c` should show the appropriate parts of 582 | the General Public License. Of course, your program's commands might be different; 583 | for a GUI interface, you would use an “about box”. 584 | 585 | You should also get your employer (if you work as a programmer) or school, if any, to 586 | sign a “copyright disclaimer” for the program, if necessary. For more 587 | information on this, and how to apply and follow the GNU GPL, see 588 | <>. 589 | 590 | The GNU General Public License does not permit incorporating your program into 591 | proprietary programs. If your program is a subroutine library, you may consider it 592 | more useful to permit linking proprietary applications with the library. If this is 593 | what you want to do, use the GNU Lesser General Public License instead of this 594 | License. But first, please read 595 | <>. 596 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(insert_table) 4 | importFrom(anytime,anydate) 5 | importFrom(assertthat,assert_that) 6 | importFrom(datapasta,tribble_construct) 7 | importFrom(miniUI,gadgetTitleBar) 8 | importFrom(miniUI,miniContentPanel) 9 | importFrom(miniUI,miniPage) 10 | importFrom(rhandsontable,rHandsontableOutput) 11 | importFrom(rhandsontable,renderRHandsontable) 12 | importFrom(rhandsontable,rhandsontable) 13 | importFrom(rstudioapi,getActiveDocumentContext) 14 | importFrom(rstudioapi,insertText) 15 | importFrom(shiny,checkboxInput) 16 | importFrom(shiny,div) 17 | importFrom(shiny,fillRow) 18 | importFrom(shiny,h4) 19 | importFrom(shiny,observeEvent) 20 | importFrom(shiny,reactiveValues) 21 | importFrom(shiny,runGadget) 22 | importFrom(shiny,selectInput) 23 | importFrom(shiny,stopApp) 24 | importFrom(shiny,wellPanel) 25 | importFrom(tools,file_ext) 26 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # inserttable 0.1 2 | 3 | Fix insertion of code in Rmd (Fixes #5) 4 | 5 | # inserttable 0.0.2 6 | 7 | * Now also working in plain ".R" files to support use in `knitr::spin` 8 | * Added possibility to provide user defined table name in the GUI 9 | 10 | # inserttable 0.0.1 11 | 12 | First stable version 13 | 14 | # inserttable 0.0.0.9000 15 | 16 | * Added a `NEWS.md` file to track changes to the package. 17 | -------------------------------------------------------------------------------- /R/WIP/create_rmd_table.R: -------------------------------------------------------------------------------- 1 | create_rmd_table <- function(table_data = NULL, 2 | nrows = NULL, 3 | ncols = NULL, 4 | colnames = NULL, 5 | tbl_format = "kable") { 6 | 7 | 8 | # ____________________________________________________________________________ 9 | # Get the data from "table_data" (if provided) and check arguments #### 10 | 11 | if (!is.null(table_data)) { 12 | assertthat::assert_that( 13 | is.data.frame(table_data), 14 | msg = strwrap("`table_data` must be a `data.frame` or something inheriting 15 | from a `data.frame` (e.g., a `data.table` or a `tibble`. 16 | Aborting!", width = 100)) 17 | nrows <- nrow(table_data) 18 | ncols <- ncol(table_data) 19 | colnames <- names(table_data) 20 | } else { 21 | assertthat::assert_that(!any(is.null(nrows), is.null(ncols)), 22 | msg = strwrap("Please specify the number of rows and 23 | columns. Aborting!", width = 100)) 24 | if (!is.null(colnames)) { 25 | assertthat::assert_that(is.character(colnames) & length(colnames = ncols), 26 | msg = "`colnames` must be a character array of 27 | length equal to `ncols`. Aborting", width = 100) 28 | } else { 29 | colnames <- paste("column", seq_len(ncols), sep = "_") 30 | } 31 | 32 | } 33 | 34 | assertthat::assert_that( 35 | tbl_format %in% c("kable", "DT", "rhandson"), 36 | msg = strwrap("`format` must be equal to `kable`, `DT` or `rhandson`. Please 37 | correct. Aborting!", width = 100)) 38 | 39 | 40 | 41 | if (tbl_format == "kable") { 42 | 43 | table_code = paste0("knitr::kable(table_data", 44 | " col.names = ", 45 | paste0("c(", 46 | paste(lapply(colnames, FUN = function(x) paste0("'", x, "'")), 47 | collapse = ", "), ")\n")) 48 | } else { 49 | if (tbl_format == "DT") { 50 | 51 | } else { 52 | 53 | } 54 | 55 | 56 | 57 | } 58 | table_code <- paste0(datapasta::tribble_construct(table_data), "\n", table_code) 59 | 60 | rstudioapi::insertText(table_code) 61 | } 62 | -------------------------------------------------------------------------------- /R/WIP/inserttable.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "test_inserttable" 3 | author: "Lorenzo Busetto" 4 | date: "24 March 2018" 5 | output: html_document 6 | --- 7 | 8 | ```{r setup, include=FALSE} 9 | knitr::opts_chunk$set(echo = TRUE) 10 | library(dplyr) 11 | ``` 12 | 13 | ## R Markdown 14 | 15 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec quam ut tortor 16 | interdum pulvinar id vitae magna. Curabitur commodo consequat arcu et lacinia. 17 | Proin at diam vitae lectus dignissim auctor nec dictum lectus. 18 | 19 | ```{r echo=FALSE, message=FALSE, warning=FALSE} 20 | 21 | iris_filtered <- iris %>% 22 | dplyr::select(1:5) %>% 23 | dplyr::filter(Petal.Width == 0.2) 24 | 25 | 26 | ``` 27 | -------------------------------------------------------------------------------- /R/get_table_code.R: -------------------------------------------------------------------------------- 1 | #' @title get_table_code 2 | #' @description Accessory function used to generate the code needed to generate 3 | #' the table in the selected output format 4 | #' @param out_tbl `list` passed from `insert_table` and containing 4 elements: 5 | #' 1: data.frame to be used to generate the table, 2: context of the call, 6 | #' 3: column names (optional) and 4: table name 7 | #' @param is_console `logical` if TRUE, the insert_table function was called 8 | #' from the console, otherwise from an Rmd file using the addin 9 | #' @param context context of the call (tells if from console or file, and if 10 | #' from file allows to retrieve the lines, etcetera) 11 | #' @return returns the code needed to generate the table, either by creating 12 | #' new lines in the Rmd, or by printing it to the console (if is.console = TRUE) 13 | #' @rdname get_table_code 14 | #' @author Lorenzo Busetto, phD (2017) 15 | #' @importFrom anytime anydate 16 | #' @importFrom datapasta tribble_construct 17 | #' @importFrom rstudioapi insertText 18 | #' 19 | get_table_code <- function(out_tbl, 20 | is_console, 21 | context) { 22 | 23 | 24 | 25 | # ____________________________________________________________________________ 26 | # Create code to generate tribble #### 27 | header <- out_tbl[[3]] 28 | tbl_name <- out_tbl[[4]] 29 | 30 | if (is.data.frame(out_tbl[[1]])) { 31 | 32 | out_tbl_data <- out_tbl[[1]] 33 | 34 | # replace column names with the first row of the table. 35 | # If the first row is empty, use col_1, col_2.... 36 | if (header) { 37 | if (length(unique(as.character(out_tbl_data[1, ]))) == ncol(out_tbl_data)) { 38 | colnames <- out_tbl_data[1, ] 39 | out_tbl_data <- out_tbl_data[-1, ] 40 | names(out_tbl_data) <- colnames 41 | } else { 42 | if (!unique(out_tbl_data[ ,1]) == "") { 43 | stop("Non-unique column names found! Aborting! ") 44 | } else { 45 | names(out_tbl_data) <- paste0("Col_", seq_len(ncol(out_tbl_data))) 46 | } 47 | } 48 | } else { 49 | names(out_tbl_data) <- paste0("Col_", seq_len(ncol(out_tbl_data))) 50 | } 51 | 52 | # convert columns to numeric if possible 53 | for (col in seq_len(ncol(out_tbl_data))) { 54 | 55 | if (!any(is.na(suppressWarnings(as.numeric(out_tbl_data[, col]))))) { 56 | out_tbl_data[, col] <- as.numeric(out_tbl_data[, col]) 57 | } else { 58 | # convert columns to "standard" date representation if possible 59 | # (i.e., YYYY-mm-dd) 60 | if (!any(is.na(anytime::anydate(out_tbl_data[, col])))) { 61 | out_tbl_data[, col] <- anytime::anydate(out_tbl_data[, col]) 62 | out_tbl_data <- as.character(out_tbl_data) 63 | } 64 | } 65 | 66 | } 67 | 68 | output_tibble_str <- paste0( 69 | tbl_name, " <- ", 70 | suppressWarnings(datapasta::tribble_construct(out_tbl_data))) 71 | } else { 72 | # In case the add-in was fired while the name of a object was selected, 73 | # or from the console, no need to add the tibble: just create code to 74 | # render a table in the specifed name using the selected format 75 | output_tibble_str <- "" 76 | } 77 | 78 | # __________________________________________________________________________ 79 | # Create code to generate table in specified format #### 80 | 81 | out_format <- out_tbl[[2]] 82 | # browser() 83 | if (out_format == "kable") { 84 | 85 | output_table_str <- 86 | paste0("require(knitr)\n", 87 | "kable(", tbl_name, ", digits = 3, row.names = FALSE, align = \"c\", 88 | caption = NULL)") 89 | } 90 | 91 | if (out_format == "kableExtra - html") { 92 | 93 | output_table_str <- 94 | paste0("require(knitr)\n", 95 | "require(kableExtra)\n", 96 | "kable_styling( 97 | kable(", tbl_name, ", digits = 3, row.names = FALSE, align = \"c\", 98 | caption = NULL, format = \"html\"), 99 | bootstrap_options = c(\"striped\", \"hover\", \"condensed\"), 100 | position = \"center\", full_width = FALSE) ") 101 | } 102 | 103 | if (out_format == "kableExtra - pdf") { 104 | 105 | output_table_str <- 106 | paste0("require(knitr)\n", 107 | "require(kableExtra)\n", 108 | "kable_styling( 109 | kable(", tbl_name, ", digits = 3, row.names = FALSE, align = \"c\", 110 | caption = NULL, format = \"latex\"), 111 | latex_options = c(\"striped\", \"basic\"), 112 | position = \"center\", full_width = FALSE) ") 113 | } 114 | 115 | if (out_format == "DT") { 116 | output_table_str <- 117 | paste0("require(DT)\n", 118 | "datatable(", tbl_name, ", rownames = FALSE, caption = NULL, 119 | filter = \"top\", escape = FALSE, style = \"default\", 120 | width = NULL, height = NULL)") 121 | } 122 | 123 | if (out_format == "rhandsontable") { 124 | output_table_str <- 125 | paste0("require(rhandsontable)\n", 126 | "rhandsontable(", tbl_name, ", rowHeaders = NULL, 127 | digits = 3, useTypes = FALSE, search = FALSE, 128 | width = NULL, height = NULL)") 129 | } 130 | 131 | if (out_format == "None") output_table_str <- "" 132 | 133 | # create the final text string to be added to the Rmd or pasted to console 134 | output_str <- paste0(output_tibble_str, "\n", output_table_str, "\n") 135 | 136 | # find the first empty line below that from which the call was made to 137 | # avoid breaking the Rmd (only if not called from console) 138 | 139 | if (!is_console) { 140 | 141 | insert_line <- NULL 142 | curr_line <- context[["selection"]][[1]][["range"]][["end"]][[1]] 143 | for (line in (curr_line):length(context$contents)) { 144 | if (context["contents"][[1]][line] == "") { 145 | insert_line <- line 146 | break() 147 | } 148 | if (context["contents"][[1]][line] == "```") { 149 | insert_line <- line - 1 150 | break() 151 | } 152 | } 153 | if (is.null(insert_line)) insert_line <- length(context$contents) - 1 154 | position <- rstudioapi::document_position(insert_line, 1) 155 | rstudioapi = rstudioapi::insertText(position,output_str) 156 | } else { 157 | rstudioapi = rstudioapi::insertText(output_str) 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /R/insert_table.R: -------------------------------------------------------------------------------- 1 | #' @title insert_table 2 | #' @description Function and RStudio add-in allowing to quickly and automatically 3 | #' generate the code needed to render a table in a RMarkdown document using different 4 | #' formats (kable, kableExtra, DT and rhandsontable are currently implemented - if "None" 5 | #' is selected only the code to generate a new tibble with the provided content 6 | #' is provided). 7 | #' @param nrows `numeric` number of rows of the generated empty table, Default: 1 8 | #' (ignored if calling the addin from an empty Rmd line) 9 | #' @param ncols `numeric` number of columns of the generated empty table, Default: 1 10 | #' (ignored if calling the addin from an empty Rmd line) 11 | #' @param tbl_format `character` [`kable` | `kableExtra - html` | `kableExtra - pdf` | 12 | #' `DT` | `rhandsontable` | `None`] format 13 | #' required for the table to be created (ignored if calling as an addin) 14 | #' @param colnames `character` of length ncols containing the desired column names 15 | #' (ignored if calling as an addin) 16 | #' @param tbl_name `character` name required for the table to be created 17 | #' (ignored if calling as an addin) 18 | #' @return returns the code required to create a table in a Rmd file with the 19 | #' required format. \cr 20 | #' When calling as an add-in: 21 | #' * if the call is done when the cursor is on a empty selection the user can 22 | #' enter also the number of rows and columns and the code to generate a empty 23 | #' tribble with the specified dimensions is also created; 24 | #' * if the call is done when the cursor is on a non-empty selection the user can 25 | #' only select the output format, and the add-in returns the code needed to 26 | #' create a table named as the selected text, with the specified format 27 | #' 28 | #' When called as a function: 29 | #' * the code to generate a empty tribble with the specified dimensions is 30 | #' created (defaults are used if any parameter is not passed), followed by 31 | #' the code needed to create a table with the specified format. The results 32 | #' are sent back to the console. 33 | #' @examples 34 | #' \dontrun{ 35 | #' # From the console, use: 36 | #' insert_table(nrows = 4, ncols = 3, tbl_format = "DT") 37 | #' 38 | #' # From a "Rmd" file and within RStudio, place the cursor on a empty line or 39 | #' # select the name a data.frame within a "R" chunk, then click on "Addins" 40 | #' # and select "Insert Table" 41 | #' } 42 | #' @rdname insert_table 43 | #' @export 44 | #' @author Lorenzo Busetto, phD (2017) 45 | #' @importFrom rstudioapi getActiveDocumentContext 46 | #' @importFrom tools file_ext 47 | #' @importFrom miniUI miniPage miniContentPanel gadgetTitleBar 48 | #' @importFrom shiny fillRow selectInput h4 div wellPanel checkboxInput reactiveValues observeEvent stopApp runGadget 49 | #' @importFrom rhandsontable rHandsontableOutput renderRHandsontable rhandsontable 50 | #' @importFrom assertthat assert_that 51 | #' 52 | insert_table = function(nrows = 3, 53 | ncols = 3, 54 | tbl_format = "kable", 55 | tbl_name = "my_tbl", 56 | colnames = NULL){ 57 | 58 | # Get the text selected when the addin was called 59 | context <- rstudioapi::getActiveDocumentContext() 60 | 61 | 62 | text <- context$selection[[1]]$text 63 | is_console <- context[["id"]] == "#console" 64 | 65 | if (!is_console) { 66 | if (text == "") { 67 | 68 | # If function called as addin from an empty line create an empty table to 69 | # initialize the GUI 70 | DT <- data.frame(matrix(data = "", ncol = 3, nrow = 4), 71 | stringsAsFactors = FALSE) 72 | 73 | out_tbl = local({ 74 | ui <- miniUI::miniPage(miniUI::miniContentPanel( 75 | miniUI::gadgetTitleBar("Select output format and edit the Table if 76 | you wish so"), 77 | shiny::fillRow( 78 | shiny::textInput('tbl_name', 'Select Table Name', value = "my_tbl"), 79 | shiny::selectInput('format', 'Select Output Format', 80 | c('kable', 'kableExtra - html', 'kableExtra - pdf', 'DT', 'rhandsontable', 'None')), 81 | height = '70px' 82 | ), 83 | shiny::h4("Edit Table or cut and paste from spreadsheet", 84 | align = "left"), 85 | shiny::div(""), 86 | shiny::div("* The first row will be used as column names.\n", 87 | style = "bold"), 88 | shiny::div("* Right click to add more lines or columns", 89 | style = "bold"), 90 | 91 | shiny::wellPanel( 92 | shiny::checkboxInput( 93 | "headers", 94 | "Use first row as column names. (If unchecked, 'Col_1', 'Col_2', etc. are used)", 95 | TRUE), 96 | rhandsontable::rHandsontableOutput("hot") 97 | ), height = "500px" 98 | 99 | 100 | )) 101 | 102 | server <- function(input,output, session){ 103 | values = shiny::reactiveValues() 104 | setHot = function(x) values[["hot"]] = DT 105 | output$hot <- rhandsontable::renderRHandsontable( 106 | rhandsontable::rhandsontable(DT, readOnly = FALSE, useTypes = FALSE, 107 | colHeaders = FALSE, 108 | allowRowEdit = TRUE)) 109 | shiny::observeEvent(input$done, { 110 | nrows <- length(input$hot$data) 111 | ncols <- unique(lengths(input$hot$data)) 112 | 113 | # https://stackoverflow.com/questions/4227223/r-list-to-data-frame 114 | data_tbl <- unlist(input$hot$data) 115 | if (is.null(data_tbl)) data_tbl <- rep(NA, nrows * ncols) 116 | DT <- data.frame(matrix(data_tbl, 117 | nrow = nrows, byrow = TRUE), 118 | stringsAsFactors = FALSE) 119 | out_tbl <- list(DT, input$format, input$headers, input$tbl_name) 120 | shiny::stopApp(returnValue = out_tbl) 121 | }) 122 | 123 | shiny::observeEvent(input$cancel, { 124 | shiny::stopApp(returnValue = "Quit") 125 | }) 126 | } 127 | shiny::runGadget(ui, server, 128 | viewer = shiny::dialogViewer("Insert Table Add-In"), 129 | stopOnCancel = FALSE) 130 | }) 131 | 132 | } else { 133 | 134 | tbl_name <- text 135 | out_tbl = local({ 136 | ui <- miniUI::miniPage(miniUI::miniContentPanel( 137 | miniUI::gadgetTitleBar("Select output format"), 138 | shiny::fillRow( 139 | shiny::textInput('tbl_name', 'Select Table Name', value = tbl_name), 140 | shiny::selectInput('format', 'Format', 141 | c('kable', 'kableExtra - html', 'kableExtra - pdf', 'DT', 'rhandsontable', 'None')), 142 | height = '70px' 143 | ) 144 | )) 145 | 146 | server = function(input, output, session) { 147 | shiny::observeEvent(input$done, { 148 | shiny::stopApp(returnValue = list("", input$format, FALSE, 149 | input$tbl_name)) 150 | }) 151 | shiny::observeEvent(input$cancel, { 152 | shiny::stopApp(returnValue = "Quit") 153 | }) 154 | } 155 | 156 | shiny::runGadget(ui, server, 157 | viewer = shiny::dialogViewer("Insert Table Add-In"), 158 | stopOnCancel = FALSE) 159 | }) 160 | } 161 | } else { 162 | # If called from console, check that all parameters were passed and are 163 | # correct 164 | 165 | assertthat::assert_that(!any(is.null(nrows), is.null(ncols), is.null(tbl_format)), 166 | msg = strwrap("Please specify the number of rows and 167 | the output format. Aborting!", 168 | width = 100)) 169 | assertthat::assert_that( 170 | tbl_format %in% c("kable", "kableExtra - html", "kableExtra - pdf", "DT", 171 | "rhandsontable", "None"), 172 | msg = strwrap("`tbl_format` must be equal to `kableExtra`, `DT` or `rhandsontable`. 173 | Please correct. Aborting!", width = 100)) 174 | 175 | if (!is.null(colnames)) { 176 | assertthat::assert_that( 177 | is.character(colnames) & all.equal(length(colnames), ncols), 178 | msg = strwrap("`colnames` must be a character array of length equal 179 | to ncols (or not provided). Aborting!", width = 100)) 180 | } 181 | 182 | out_tbl <- data.frame(matrix("", nrow = nrows, ncol = ncols), 183 | stringsAsFactors = FALSE) 184 | if (is.null(colnames)) { 185 | names(out_tbl) <- paste0("col_", seq_len(ncols)) 186 | } else { 187 | names(out_tbl) <- colnames 188 | } 189 | 190 | out_tbl <- list(out_tbl, tbl_format, FALSE, tbl_name) 191 | 192 | } 193 | 194 | if (!is.character(out_tbl)) { 195 | get_table_code(out_tbl, 196 | is_console, 197 | context) 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | inserttable 5 | 6 | 7 | [![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) 8 | [![Travis-CI Build Status](https://travis-ci.org/lbusett/insert_table.svg?branch=master)](https://travis-ci.org/ropensci/insert_table) 9 | 10 | 11 | 12 | 13 | ```{r setup, include = FALSE} 14 | knitr::opts_chunk$set( 15 | collapse = TRUE, 16 | comment = "#>", 17 | fig.path = "man/figures/README-", 18 | out.width = "100%" 19 | ) 20 | ``` 21 | # inserttable 22 | 23 | `inserttable` is an RStudio add-in facilitating insertion of nicely formatted 24 | tables in R markdown documents or plain R scripts. 25 | 26 | ## Installation 27 | 28 | You can install `inserttable` from [GitHub](https://github.com/lbusett/insert_table) 29 | with: 30 | 31 | ``` r 32 | # install.packages("devtools") 33 | devtools::install_github("lbusett/insert_table") 34 | ``` 35 | 36 | ## Usage 37 | 38 | Upon installing, `inserttable` registers a new RStudio Addin (__Insert Table__) 39 | that can be used to easily insert a table in a `Rmd` document. To use it, open a 40 | `Rmd` or `R` document and select "Addins --> Insert Table". 41 | 42 | There are two main __use modes__: 43 | 44 | 45 | ### Launch the addin with the cursor on a empty line 46 | 47 | In this case, a GUI will open allowing you to __select the desired output format__ ( 48 | `kable`, `kableExtra`, `DT` and `rhandsontable` are currently implemented), and to __edit the 49 | content of the table__. After clicking __Done__ the Addin will add in the file 50 | the code needed to generate the table in a nice `tribble` format (thanks 51 | to Miles McBain's [`datapasta`](https://github.com/milesmcbain/datapasta) package!) 52 | to allow easier additional editing, and also the code needed to render it with the selected 53 | output format using some default options, as can be seen below: 54 | 55 | __IMPORTANT NOTE:__ Not all output formats play well with knitting to PDF or Word!. 56 | `kable` works everywhere, while `DT` and `rhandsontable` work out of the box only 57 | if knitting to html. You can make them work on PDF and Word by adding 58 | `always_allow_html: yes` in the yaml header of the Rmd, and installing __phantomjs__ using: 59 | `webshot::install_phantomjs()` (results are not that good, though). 60 | 61 | ![](man/figures/animation_1.gif) 62 | 63 | 64 | A useful feature is that, for larger tables, you can also __cut and paste content from a spreadsheet__ : 65 | 66 | ![](man/figures/animation_2.gif) 67 | 68 | 69 | Obviously, rendering of the table can be tweaked further by changing/adding arguments of the rendering functions in the automatically generated code. 70 | 71 | 72 | ### Launch the addin while selecting the name of a variable 73 | 74 | In this case, the GUI allows you to select __only the desired output format__ ( 75 | it is assumed that the variable you select corresponds to a `data frame` or similar 76 | object containing the data you wish to show as table). After clicking __Done__ 77 | the Addin will add in the `Rmd` document the code needed to render the selected variable as a table with the selected output format. The code will be added at the first empty line below that containing the name of the selected variable. 78 | 79 | 80 | ![](man/figures/animation_3.gif) 81 | 82 | 83 | __IMPORTANT NOTE__: `inserttable` will make no effort to guarantee that the 84 | variable you select is a `data.frame`. It is up to you to select a meaningful 85 | variable! 86 | 87 | 88 | ## Usage from the console 89 | 90 | You can also use (part of) `inserttable` functionality from the console by calling 91 | function `insert_table()`. 92 | 93 | ```{r eval=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE} 94 | > insert_table(tbl_name = "table_1", nrows = 4, ncols = 4, tbl_format = "DT") 95 | 96 | ``` 97 | 98 | The function will return __to the console__ the code needed to create a empty 99 | table of the specified dimensions and render it with the selected format: 100 | 101 | ![](man/figures/animation_4.gif) 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | inserttable 3 | 4 | 5 | 6 | 7 | [![Lifecycle: 8 | maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) 9 | [![Travis-CI Build 10 | Status](https://travis-ci.org/lbusett/insert_table.svg?branch=master)](https://travis-ci.org/ropensci/insert_table) 11 | 12 | 13 | 14 | 15 | # inserttable 16 | 17 | `inserttable` is an RStudio add-in facilitating insertion of nicely 18 | formatted tables in R markdown documents or plain R scripts. 19 | 20 | ## Installation 21 | 22 | You can install `inserttable` from 23 | [GitHub](https://github.com/lbusett/insert_table) with: 24 | 25 | ``` r 26 | # install.packages("devtools") 27 | devtools::install_github("lbusett/insert_table") 28 | ``` 29 | 30 | ## Usage 31 | 32 | Upon installing, `inserttable` registers a new RStudio Addin (**Insert 33 | Table**) that can be used to easily insert a table in a `Rmd` document. 34 | To use it, open a `Rmd` or `R` document and select “Addins –\> Insert 35 | Table”. 36 | 37 | There are two main **use modes**: 38 | 39 | ### Launch the addin with the cursor on a empty line 40 | 41 | In this case, a GUI will open allowing you to **select the desired 42 | output format** ( `kable`, `kableExtra`, `DT` and `rhandsontable` are 43 | currently implemented), and to **edit the content of the table**. After 44 | clicking **Done** the Addin will add in the file the code needed to 45 | generate the table in a nice `tribble` format (thanks to Miles McBain’s 46 | [`datapasta`](https://github.com/milesmcbain/datapasta) package\!) to 47 | allow easier additional editing, and also the code needed to render it 48 | with the selected output format using some default options, as can be 49 | seen below: 50 | 51 | **IMPORTANT NOTE:** Not all output formats play well with knitting to 52 | PDF or Word\!. `kable` works everywhere, while `DT` and `rhandsontable` 53 | work out of the box only if knitting to html. You can make them work on 54 | PDF and Word by adding `always_allow_html: yes` in the yaml header of 55 | the Rmd, and installing **phantomjs** using: 56 | `webshot::install_phantomjs()` (results are not that good, though). 57 | 58 | ![](man/figures/animation_1.gif) 59 | 60 | A useful feature is that, for larger tables, you can also **cut and 61 | paste content from a spreadsheet** : 62 | 63 | ![](man/figures/animation_2.gif) 64 | 65 | Obviously, rendering of the table can be tweaked further by 66 | changing/adding arguments of the rendering functions in the 67 | automatically generated code. 68 | 69 | ### Launch the addin while selecting the name of a variable 70 | 71 | In this case, the GUI allows you to select **only the desired output 72 | format** ( it is assumed that the variable you select corresponds to a 73 | `data frame` or similar object containing the data you wish to show as 74 | table). After clicking **Done** the Addin will add in the `Rmd` document 75 | the code needed to render the selected variable as a table with the 76 | selected output format. The code will be added at the first empty line 77 | below that containing the name of the selected variable. 78 | 79 | ![](man/figures/animation_3.gif) 80 | 81 | **IMPORTANT NOTE**: `inserttable` will make no effort to guarantee that 82 | the variable you select is a `data.frame`. It is up to you to select a 83 | meaningful variable\! 84 | 85 | ## Usage from the console 86 | 87 | You can also use (part of) `inserttable` functionality from the console 88 | by calling function 89 | `insert_table()`. 90 | 91 | ``` r 92 | > insert_table(tbl_name = "table_1", nrows = 4, ncols = 4, tbl_format = "DT") 93 | ``` 94 | 95 | The function will return **to the console** the code needed to create a 96 | empty table of the specified dimensions and render it with the selected 97 | format: 98 | 99 | ![](man/figures/animation_4.gif) 100 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | destination: docs 2 | url: https://lbusett.github.io/insert_table/ 3 | template: 4 | params: 5 | bootswatch: spacelab 6 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
67 |
68 | 110 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 | Content not found. Please use links in the navbar. 122 | 123 |
124 | 125 |
126 | 127 | 128 | 129 |
130 | 133 | 134 |
135 |

Site built with pkgdown 1.4.1.

136 |
137 | 138 |
139 |
140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/Index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | inserttable • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
67 |
68 | 110 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 |
122 | 123 |

inserttable is an RStudio add-in facilitating insertion of nicely formatted tables in R markdown documents or plain R scripts.

124 |
125 |

126 | Installation

127 |

You can install inserttable from GitHub with:

128 | 130 |
131 |
132 |

133 | Usage

134 |

Upon installing, inserttable registers a new RStudio Addin (Insert Table) that can be used to easily insert a table in a Rmd document. To use it, open a Rmd document and, with the cursor within a r chunk and select “Addins –> Insert Table”.

135 |

These are the two main use modes:

136 |
137 |

138 | Launch the addin with the cursor on a empty line

139 |

In this case, a GUI will open allowing you to select the desired output format ( kableExtra, DT and rhandsontable are currently implemented), and to edit the content of the table. After clicking Done the Addin will add in the file the code needed to generate the table in a nice tribble format (thanks to Miles McBain’s datapasta package!) to allow easier additional editing, and also the code needed to render it with the selected output format using some default options, as can be seen below:

140 |

IMPORTANT NOTE: Not all output formats play well with knitting to PDF or Word!. kable works everywhere, while DT and rhandsontable work out of the box only if knitting to html. You can make them work on PDF and Word by adding always_allow_html: yes in the yaml header of the Rmd, and installing phantomjs using: webshot::install_phantomjs() (results are not that good, though).

141 |

142 |

A useful feature is that, for larger tables, you can also cut and paste content from a spreadsheet :

143 |

144 |

Obviously, rendering of the table can be tweaked further by changing/adding arguments of the rendering functions in the automatically generated code.

145 |
146 |
147 |

148 | Launch the addin while selecting the name of a variable

149 |

In this case, the GUI allows you to select only the desired output format ( it is assumed that the variable you select corresponds to a data frame or similar object containing the data you wish to show as table). After clicking Done the Addin will add in the Rmd document the code needed to render the selected variable as a table with the selected output format. The code will be added at the first empty line below that containing the name of the selected variable.

150 |

151 |

IMPORTANT NOTE: inserttable will make no effort to guarantee that the variable you select is a data.frame. It is up to you to select a meaningful variable!

152 |
153 |
154 |
155 |

156 | Usage from the console

157 |

You can also use (part of) inserttable functionality from the console by calling function insert_table().

158 |

159 | > insert_table(tbl_name = "table_1", nrows = 4, ncols = 4, tbl_format = "DT")
160 |

The function will return to the console the code needed to create a empty table of the specified dimensions and render it with the selected format:

161 |

162 |
163 |
164 | 165 |
166 | 167 |
168 | 169 | 170 | 171 |
172 | 175 | 176 |
177 |

Site built with pkgdown 1.4.1.

178 |
179 | 180 |
181 |
182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | 97 | 98 | 99 |
100 | 101 |
102 |
103 | 106 | 107 |
YEAR: 2018
108 | COPYRIGHT HOLDER: Lorenzo Busetto
109 | 
110 | 111 |
112 | 113 |
114 | 115 | 116 |
117 | 120 | 121 |
122 |

Site built with pkgdown.

123 |
124 | 125 |
126 |
127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | 100 | 101 | 102 |
103 | 104 |
105 |
106 | 109 | 110 |
111 |

All vignettes

112 |

113 | 114 | 117 |
118 |
119 |
120 | 121 |
122 | 125 | 126 |
127 |

Site built with pkgdown.

128 |
129 | 130 |
131 |
132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /docs/articles/inserttable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Vignette Title • inserttable 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 |
22 |
75 | 76 | 77 | 78 |
79 |
80 | 89 | 90 | 91 | 92 |

Vignettes are long form documentation commonly included in packages. Because they are part of the distribution of the package, they need to be as compact as possible. The html_vignette output type provides a custom style sheet (and tweaks some options) to ensure that the resulting html is as small as possible. The html_vignette format:

93 |
    94 |
  • Never uses retina figures
  • 95 |
  • Has a smaller default figure size
  • 96 |
  • Uses a custom CSS stylesheet instead of the default Twitter Bootstrap style
  • 97 |
98 |
99 |

100 | Vignette Info

101 |

Note the various macros within the vignette section of the metadata block above. These are required in order to instruct R how to build the vignette. Note that you should change the title field and the \VignetteIndexEntry to match the title of your vignette.

102 |
103 |
104 |

105 | Styles

106 |

The html_vignette template includes a basic CSS theme. To override this theme you can specify your own CSS in the document metadata as follows:

107 |
output: 
108 |   rmarkdown::html_vignette:
109 |     css: mystyles.css
110 |
111 |
112 |

113 | Figures

114 |

The figure sizes have been customised so that you can easily put two images side-by-side.

115 |
plot(1:10)
116 | plot(10:1)
117 |

118 |

You can enable figure captions by fig_caption: yes in YAML:

119 |
output:
120 |   rmarkdown::html_vignette:
121 |     fig_caption: yes
122 |

Then you can use the chunk option fig.cap = "Your figure caption." in knitr.

123 |
124 |
125 |

126 | More Examples

127 |

You can write math expressions, e.g. \(Y = X\beta + \epsilon\), footnotes1, and tables, e.g. using knitr::kable().

128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 |
mpgcyldisphpdratwtqsecvsamgearcarb
Mazda RX421.06160.01103.902.62016.460144
Mazda RX4 Wag21.06160.01103.902.87517.020144
Datsun 71022.84108.0933.852.32018.611141
Hornet 4 Drive21.46258.01103.083.21519.441031
Hornet Sportabout18.78360.01753.153.44017.020032
Valiant18.16225.01052.763.46020.221031
Duster 36014.38360.02453.213.57015.840034
Merc 240D24.44146.7623.693.19020.001042
Merc 23022.84140.8953.923.15022.901042
Merc 28019.26167.61233.923.44018.301044
286 |

Also a quote using >:

287 |
288 |

“He who gives up [code] safety for [code] speed deserves neither.” (via)

289 |
290 |
291 |
292 |
293 |
    294 |
  1. A footnote here.

  2. 295 |
296 |
297 |
298 | 299 | 311 | 312 |
313 | 314 | 315 |
318 | 319 |
320 |

Site built with pkgdown.

321 |
322 | 323 |
324 |
325 | 326 | 327 | 328 | 329 | 330 | -------------------------------------------------------------------------------- /docs/articles/inserttable_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/articles/inserttable_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/inserttable_files/figure-html/unnamed-chunk-1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/articles/inserttable_files/figure-html/unnamed-chunk-1-2.png -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
67 |
68 | 110 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 |
    122 |
  • 123 |

    Lorenzo Busetto. Author, maintainer. ORCID 124 |

    125 |
  • 126 |
127 | 128 |
129 | 130 |
131 | 132 | 133 | 134 |
135 | 138 | 139 |
140 |

Site built with pkgdown 1.4.1.

141 |
142 | 143 |
144 |
145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /docs/docsearch.css: -------------------------------------------------------------------------------- 1 | /* Docsearch -------------------------------------------------------------- */ 2 | /* 3 | Source: https://github.com/algolia/docsearch/ 4 | License: MIT 5 | */ 6 | 7 | .algolia-autocomplete { 8 | display: block; 9 | -webkit-box-flex: 1; 10 | -ms-flex: 1; 11 | flex: 1 12 | } 13 | 14 | .algolia-autocomplete .ds-dropdown-menu { 15 | width: 100%; 16 | min-width: none; 17 | max-width: none; 18 | padding: .75rem 0; 19 | background-color: #fff; 20 | background-clip: padding-box; 21 | border: 1px solid rgba(0, 0, 0, .1); 22 | box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); 23 | } 24 | 25 | @media (min-width:768px) { 26 | .algolia-autocomplete .ds-dropdown-menu { 27 | width: 175% 28 | } 29 | } 30 | 31 | .algolia-autocomplete .ds-dropdown-menu::before { 32 | display: none 33 | } 34 | 35 | .algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { 36 | padding: 0; 37 | background-color: rgb(255,255,255); 38 | border: 0; 39 | max-height: 80vh; 40 | } 41 | 42 | .algolia-autocomplete .ds-dropdown-menu .ds-suggestions { 43 | margin-top: 0 44 | } 45 | 46 | .algolia-autocomplete .algolia-docsearch-suggestion { 47 | padding: 0; 48 | overflow: visible 49 | } 50 | 51 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 52 | padding: .125rem 1rem; 53 | margin-top: 0; 54 | font-size: 1.3em; 55 | font-weight: 500; 56 | color: #00008B; 57 | border-bottom: 0 58 | } 59 | 60 | .algolia-autocomplete .algolia-docsearch-suggestion--wrapper { 61 | float: none; 62 | padding-top: 0 63 | } 64 | 65 | .algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { 66 | float: none; 67 | width: auto; 68 | padding: 0; 69 | text-align: left 70 | } 71 | 72 | .algolia-autocomplete .algolia-docsearch-suggestion--content { 73 | float: none; 74 | width: auto; 75 | padding: 0 76 | } 77 | 78 | .algolia-autocomplete .algolia-docsearch-suggestion--content::before { 79 | display: none 80 | } 81 | 82 | .algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { 83 | padding-top: .75rem; 84 | margin-top: .75rem; 85 | border-top: 1px solid rgba(0, 0, 0, .1) 86 | } 87 | 88 | .algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { 89 | display: block; 90 | padding: .1rem 1rem; 91 | margin-bottom: 0.1; 92 | font-size: 1.0em; 93 | font-weight: 400 94 | /* display: none */ 95 | } 96 | 97 | .algolia-autocomplete .algolia-docsearch-suggestion--title { 98 | display: block; 99 | padding: .25rem 1rem; 100 | margin-bottom: 0; 101 | font-size: 0.9em; 102 | font-weight: 400 103 | } 104 | 105 | .algolia-autocomplete .algolia-docsearch-suggestion--text { 106 | padding: 0 1rem .5rem; 107 | margin-top: -.25rem; 108 | font-size: 0.8em; 109 | font-weight: 400; 110 | line-height: 1.25 111 | } 112 | 113 | .algolia-autocomplete .algolia-docsearch-footer { 114 | width: 110px; 115 | height: 20px; 116 | z-index: 3; 117 | margin-top: 10.66667px; 118 | float: right; 119 | font-size: 0; 120 | line-height: 0; 121 | } 122 | 123 | .algolia-autocomplete .algolia-docsearch-footer--logo { 124 | background-image: url("data:image/svg+xml;utf8,"); 125 | background-repeat: no-repeat; 126 | background-position: 50%; 127 | background-size: 100%; 128 | overflow: hidden; 129 | text-indent: -9000px; 130 | width: 100%; 131 | height: 100%; 132 | display: block; 133 | transform: translate(-8px); 134 | } 135 | 136 | .algolia-autocomplete .algolia-docsearch-suggestion--highlight { 137 | color: #FF8C00; 138 | background: rgba(232, 189, 54, 0.1) 139 | } 140 | 141 | 142 | .algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { 143 | box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) 144 | } 145 | 146 | .algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { 147 | background-color: rgba(192, 192, 192, .15) 148 | } 149 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/favicon.ico -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Automatically Add a Table to a RMarkdown Document • inserttable 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 29 | 30 | 31 |
32 |
75 | 76 | 77 | 78 | 79 |
80 |
81 | 82 |

inserttable

83 | 84 | 85 | 86 |
87 | 89 |

inserttable is an RStudio add-in facilitating insertion of nicely formatted tables in R markdown documents or plain R scripts.

90 |
91 |

92 | Installation

93 |

You can install inserttable from GitHub with:

94 | 96 |
97 |
98 |

99 | Usage

100 |

Upon installing, inserttable registers a new RStudio Addin (Insert Table) that can be used to easily insert a table in a Rmd document. To use it, open a Rmd or R document and select “Addins –> Insert Table”.

101 |

There are two main use modes:

102 |
103 |

104 | Launch the addin with the cursor on a empty line

105 |

In this case, a GUI will open allowing you to select the desired output format ( kable, kableExtra, DT and rhandsontable are currently implemented), and to edit the content of the table. After clicking Done the Addin will add in the file the code needed to generate the table in a nice tribble format (thanks to Miles McBain’s datapasta package!) to allow easier additional editing, and also the code needed to render it with the selected output format using some default options, as can be seen below:

106 |

IMPORTANT NOTE: Not all output formats play well with knitting to PDF or Word!. kable works everywhere, while DT and rhandsontable work out of the box only if knitting to html. You can make them work on PDF and Word by adding always_allow_html: yes in the yaml header of the Rmd, and installing phantomjs using: webshot::install_phantomjs() (results are not that good, though).

107 |

108 |

A useful feature is that, for larger tables, you can also cut and paste content from a spreadsheet :

109 |

110 |

Obviously, rendering of the table can be tweaked further by changing/adding arguments of the rendering functions in the automatically generated code.

111 |
112 |
113 |

114 | Launch the addin while selecting the name of a variable

115 |

In this case, the GUI allows you to select only the desired output format ( it is assumed that the variable you select corresponds to a data frame or similar object containing the data you wish to show as table). After clicking Done the Addin will add in the Rmd document the code needed to render the selected variable as a table with the selected output format. The code will be added at the first empty line below that containing the name of the selected variable.

116 |

117 |

IMPORTANT NOTE: inserttable will make no effort to guarantee that the variable you select is a data.frame. It is up to you to select a meaningful variable!

118 |
119 |
120 |
121 |

122 | Usage from the console

123 |

You can also use (part of) inserttable functionality from the console by calling function insert_table().

124 |
> insert_table(tbl_name = "table_1", nrows = 4, ncols = 4, tbl_format = "DT")
125 |

The function will return to the console the code needed to create a empty table of the specified dimensions and render it with the selected format:

126 |

127 |
128 |
129 | 130 |
131 | 132 | 164 |
165 | 166 | 167 |
170 | 171 |
172 |

Site built with pkgdown 1.4.1.

173 |
174 | 175 |
176 |
177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /docs/jquery.sticky-kit.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net 3 | */ 4 | (function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); 5 | if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
"))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, 6 | u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), 8 | a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", 9 | y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/logo.png -------------------------------------------------------------------------------- /docs/man/Figures/animation_1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/man/Figures/animation_1.gif -------------------------------------------------------------------------------- /docs/man/Figures/animation_2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/man/Figures/animation_2.gif -------------------------------------------------------------------------------- /docs/man/Figures/animation_3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/man/Figures/animation_3.gif -------------------------------------------------------------------------------- /docs/man/Figures/animation_4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/man/Figures/animation_4.gif -------------------------------------------------------------------------------- /docs/news/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Changelog • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
67 |
68 | 110 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 121 | 122 |
123 |

124 | inserttable 0.1

125 |

Fix insertion of code in Rmd (Fixes #5)

126 |
127 |
128 |

129 | inserttable 0.0.2

130 |
    131 |
  • Now also working in plain “.R” files to support use in knitr::spin 132 |
  • 133 |
  • Added possibility to provide user defined table name in the GUI
  • 134 |
135 |
136 |
137 |

138 | inserttable 0.0.1

139 |

First stable version

140 |
141 |
142 |

143 | inserttable 0.0.0.9000

144 |
    145 |
  • Added a NEWS.md file to track changes to the package.
  • 146 |
147 |
148 |
149 | 150 | 161 | 162 |
163 | 164 | 165 |
166 | 169 | 170 |
171 |

Site built with pkgdown 1.4.1.

172 |
173 | 174 |
175 |
176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body > .container { 21 | display: flex; 22 | height: 100%; 23 | flex-direction: column; 24 | } 25 | 26 | body > .container .row { 27 | flex: 1 0 auto; 28 | } 29 | 30 | footer { 31 | margin-top: 45px; 32 | padding: 35px 0 36px; 33 | border-top: 1px solid #e5e5e5; 34 | color: #666; 35 | display: flex; 36 | flex-shrink: 0; 37 | } 38 | footer p { 39 | margin-bottom: 0; 40 | } 41 | footer div { 42 | flex: 1; 43 | } 44 | footer .pkgdown { 45 | text-align: right; 46 | } 47 | footer p { 48 | margin-bottom: 0; 49 | } 50 | 51 | img.icon { 52 | float: right; 53 | } 54 | 55 | img { 56 | max-width: 100%; 57 | } 58 | 59 | /* Fix bug in bootstrap (only seen in firefox) */ 60 | summary { 61 | display: list-item; 62 | } 63 | 64 | /* Typographic tweaking ---------------------------------*/ 65 | 66 | .contents .page-header { 67 | margin-top: calc(-60px + 1em); 68 | } 69 | 70 | /* Section anchors ---------------------------------*/ 71 | 72 | a.anchor { 73 | margin-left: -30px; 74 | display:inline-block; 75 | width: 30px; 76 | height: 30px; 77 | visibility: hidden; 78 | 79 | background-image: url(./link.svg); 80 | background-repeat: no-repeat; 81 | background-size: 20px 20px; 82 | background-position: center center; 83 | } 84 | 85 | .hasAnchor:hover a.anchor { 86 | visibility: visible; 87 | } 88 | 89 | @media (max-width: 767px) { 90 | .hasAnchor:hover a.anchor { 91 | visibility: hidden; 92 | } 93 | } 94 | 95 | 96 | /* Fixes for fixed navbar --------------------------*/ 97 | 98 | .contents h1, .contents h2, .contents h3, .contents h4 { 99 | padding-top: 60px; 100 | margin-top: -40px; 101 | } 102 | 103 | /* Sidebar --------------------------*/ 104 | 105 | #sidebar { 106 | margin-top: 30px; 107 | position: -webkit-sticky; 108 | position: sticky; 109 | top: 70px; 110 | } 111 | #sidebar h2 { 112 | font-size: 1.5em; 113 | margin-top: 1em; 114 | } 115 | 116 | #sidebar h2:first-child { 117 | margin-top: 0; 118 | } 119 | 120 | #sidebar .list-unstyled li { 121 | margin-bottom: 0.5em; 122 | } 123 | 124 | .orcid { 125 | height: 16px; 126 | /* margins are required by official ORCID trademark and display guidelines */ 127 | margin-left:4px; 128 | margin-right:4px; 129 | vertical-align: middle; 130 | } 131 | 132 | /* Reference index & topics ----------------------------------------------- */ 133 | 134 | .ref-index th {font-weight: normal;} 135 | 136 | .ref-index td {vertical-align: top;} 137 | .ref-index .icon {width: 40px;} 138 | .ref-index .alias {width: 40%;} 139 | .ref-index-icons .alias {width: calc(40% - 40px);} 140 | .ref-index .title {width: 60%;} 141 | 142 | .ref-arguments th {text-align: right; padding-right: 10px;} 143 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 144 | .ref-arguments .name {width: 20%;} 145 | .ref-arguments .desc {width: 80%;} 146 | 147 | /* Nice scrolling for wide elements --------------------------------------- */ 148 | 149 | table { 150 | display: block; 151 | overflow: auto; 152 | } 153 | 154 | /* Syntax highlighting ---------------------------------------------------- */ 155 | 156 | pre { 157 | word-wrap: normal; 158 | word-break: normal; 159 | border: 1px solid #eee; 160 | } 161 | 162 | pre, code { 163 | background-color: #f8f8f8; 164 | color: #333; 165 | } 166 | 167 | pre code { 168 | overflow: auto; 169 | word-wrap: normal; 170 | white-space: pre; 171 | } 172 | 173 | pre .img { 174 | margin: 5px 0; 175 | } 176 | 177 | pre .img img { 178 | background-color: #fff; 179 | display: block; 180 | height: auto; 181 | } 182 | 183 | code a, pre a { 184 | color: #375f84; 185 | } 186 | 187 | a.sourceLine:hover { 188 | text-decoration: none; 189 | } 190 | 191 | .fl {color: #1514b5;} 192 | .fu {color: #000000;} /* function */ 193 | .ch,.st {color: #036a07;} /* string */ 194 | .kw {color: #264D66;} /* keyword */ 195 | .co {color: #888888;} /* comment */ 196 | 197 | .message { color: black; font-weight: bolder;} 198 | .error { color: orange; font-weight: bolder;} 199 | .warning { color: #6A0366; font-weight: bolder;} 200 | 201 | /* Clipboard --------------------------*/ 202 | 203 | .hasCopyButton { 204 | position: relative; 205 | } 206 | 207 | .btn-copy-ex { 208 | position: absolute; 209 | right: 0; 210 | top: 0; 211 | visibility: hidden; 212 | } 213 | 214 | .hasCopyButton:hover button.btn-copy-ex { 215 | visibility: visible; 216 | } 217 | 218 | /* headroom.js ------------------------ */ 219 | 220 | .headroom { 221 | will-change: transform; 222 | transition: transform 200ms linear; 223 | } 224 | .headroom--pinned { 225 | transform: translateY(0%); 226 | } 227 | .headroom--unpinned { 228 | transform: translateY(-100%); 229 | } 230 | 231 | /* mark.js ----------------------------*/ 232 | 233 | mark { 234 | background-color: rgba(255, 255, 51, 0.5); 235 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 236 | padding: 1px; 237 | } 238 | 239 | /* vertical spacing after htmlwidgets */ 240 | .html-widget { 241 | margin-bottom: 10px; 242 | } 243 | 244 | /* fontawesome ------------------------ */ 245 | 246 | .fab { 247 | font-family: "Font Awesome 5 Brands" !important; 248 | } 249 | 250 | /* don't display links in code chunks when printing */ 251 | /* source: https://stackoverflow.com/a/10781533 */ 252 | @media print { 253 | code a:link:after, code a:visited:after { 254 | content: ""; 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('body').scrollspy({ 13 | target: '#sidebar', 14 | offset: 60 15 | }); 16 | 17 | $('[data-toggle="tooltip"]').tooltip(); 18 | 19 | var cur_path = paths(location.pathname); 20 | var links = $("#navbar ul li a"); 21 | var max_length = -1; 22 | var pos = -1; 23 | for (var i = 0; i < links.length; i++) { 24 | if (links[i].getAttribute("href") === "#") 25 | continue; 26 | // Ignore external links 27 | if (links[i].host !== location.host) 28 | continue; 29 | 30 | var nav_path = paths(links[i].pathname); 31 | 32 | var length = prefix_length(nav_path, cur_path); 33 | if (length > max_length) { 34 | max_length = length; 35 | pos = i; 36 | } 37 | } 38 | 39 | // Add class to parent
  • , and enclosing
  • if in dropdown 40 | if (pos >= 0) { 41 | var menu_anchor = $(links[pos]); 42 | menu_anchor.parent().addClass("active"); 43 | menu_anchor.closest("li.dropdown").addClass("active"); 44 | } 45 | }); 46 | 47 | function paths(pathname) { 48 | var pieces = pathname.split("/"); 49 | pieces.shift(); // always starts with / 50 | 51 | var end = pieces[pieces.length - 1]; 52 | if (end === "index.html" || end === "") 53 | pieces.pop(); 54 | return(pieces); 55 | } 56 | 57 | // Returns -1 if not found 58 | function prefix_length(needle, haystack) { 59 | if (needle.length > haystack.length) 60 | return(-1); 61 | 62 | // Special case for length-0 haystack, since for loop won't run 63 | if (haystack.length === 0) { 64 | return(needle.length === 0 ? 0 : -1); 65 | } 66 | 67 | for (var i = 0; i < haystack.length; i++) { 68 | if (needle[i] != haystack[i]) 69 | return(i); 70 | } 71 | 72 | return(haystack.length); 73 | } 74 | 75 | /* Clipboard --------------------------*/ 76 | 77 | function changeTooltipMessage(element, msg) { 78 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 79 | element.setAttribute('data-original-title', msg); 80 | $(element).tooltip('show'); 81 | element.setAttribute('data-original-title', tooltipOriginalTitle); 82 | } 83 | 84 | if(ClipboardJS.isSupported()) { 85 | $(document).ready(function() { 86 | var copyButton = ""; 87 | 88 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 89 | 90 | // Insert copy buttons: 91 | $(copyButton).prependTo(".hasCopyButton"); 92 | 93 | // Initialize tooltips: 94 | $('.btn-copy-ex').tooltip({container: 'body'}); 95 | 96 | // Initialize clipboard: 97 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 98 | text: function(trigger) { 99 | return trigger.parentNode.textContent; 100 | } 101 | }); 102 | 103 | clipboardBtnCopies.on('success', function(e) { 104 | changeTooltipMessage(e.trigger, 'Copied!'); 105 | e.clearSelection(); 106 | }); 107 | 108 | clipboardBtnCopies.on('error', function() { 109 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 110 | }); 111 | }); 112 | } 113 | })(window.jQuery || window.$) 114 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.3.1 2 | pkgdown: 1.4.1 3 | pkgdown_sha: ~ 4 | articles: {} 5 | urls: 6 | reference: https://lbusett.github.io/insert_table//reference 7 | article: https://lbusett.github.io/insert_table//articles 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/figures/animation_1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/reference/figures/animation_1.gif -------------------------------------------------------------------------------- /docs/reference/figures/animation_2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/reference/figures/animation_2.gif -------------------------------------------------------------------------------- /docs/reference/figures/animation_3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/reference/figures/animation_3.gif -------------------------------------------------------------------------------- /docs/reference/figures/animation_4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/reference/figures/animation_4.gif -------------------------------------------------------------------------------- /docs/reference/figures/insert-table.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/reference/get_table_code.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | get_table_code — get_table_code • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
    69 |
    70 | 112 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 |

    Accessory function used to generate the code needed to generate 127 | the table in the selected output format

    128 |
    129 | 130 |
    get_table_code(out_tbl, is_console, context)
    131 | 132 |

    Arguments

    133 | 134 | 135 | 136 | 137 | 140 | 141 | 142 | 143 | 145 | 146 | 147 | 148 | 150 | 151 |
    out_tbl

    `list` passed from `insert_table` and containing 4 elements: 138 | 1: data.frame to be used to generate the table, 2: context of the call, 139 | 3: column names (optional) and 4: table name

    is_console

    `logical` if TRUE, the insert_table function was called 144 | from the console, otherwise from an Rmd file using the addin

    context

    context of the call (tells if from console or file, and if 149 | from file allows to retrieve the lines, etcetera)

    152 | 153 |

    Value

    154 | 155 |

    returns the code needed to generate the table, either by creating 156 | new lines in the Rmd, or by printing it to the console (if is.console = TRUE)

    157 | 158 |
    159 | 169 |
    170 | 171 | 172 |
    173 | 176 | 177 |
    178 |

    Site built with pkgdown 1.4.1.

    179 |
    180 | 181 |
    182 |
    183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Function reference • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
    67 |
    68 | 110 | 111 | 112 | 113 |
    114 | 115 |
    116 |
    117 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 135 | 136 | 137 | 138 | 141 | 142 | 143 | 144 | 147 | 148 | 149 | 150 |
    132 |

    All functions

    133 |

    134 |
    139 |

    get_table_code()

    140 |

    get_table_code

    145 |

    insert_table()

    146 |

    insert_table

    151 |
    152 | 153 | 159 |
    160 | 161 | 162 |
    163 | 166 | 167 |
    168 |

    Site built with pkgdown 1.4.1.

    169 |
    170 | 171 |
    172 |
    173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /docs/reference/insert_table.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | insert_table — insert_table • inserttable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
    72 |
    73 | 115 | 116 | 117 | 118 |
    119 | 120 |
    121 |
    122 | 127 | 128 |
    129 |

    Function and RStudio add-in allowing to quickly and automatically 130 | generate the code needed to render a table in a RMarkdown document using different 131 | formats (kable, kableExtra, DT and rhandsontable are currently implemented - if "None" 132 | is selected only the code to generate a new tibble with the provided content 133 | is provided).

    134 |
    135 | 136 |
    insert_table(nrows = 3, ncols = 3, tbl_format = "kable",
    137 |   tbl_name = "my_tbl", colnames = NULL)
    138 | 139 |

    Arguments

    140 | 141 | 142 | 143 | 144 | 146 | 147 | 148 | 149 | 151 | 152 | 153 | 154 | 157 | 158 | 159 | 160 | 162 | 163 | 164 | 165 | 167 | 168 |
    nrows

    `numeric` number of rows of the generated empty table, Default: 1 145 | (ignored if calling the addin from an empty Rmd line)

    ncols

    `numeric` number of columns of the generated empty table, Default: 1 150 | (ignored if calling the addin from an empty Rmd line)

    tbl_format

    `character` [`kable` | `kableExtra - html` | `kableExtra - pdf` | 155 | `DT` | `rhandsontable` | `None`] format 156 | required for the table to be created (ignored if calling as an addin)

    tbl_name

    `character` name required for the table to be created 161 | (ignored if calling as an addin)

    colnames

    `character` of length ncols containing the desired column names 166 | (ignored if calling as an addin)

    169 | 170 |

    Value

    171 | 172 |

    returns the code required to create a table in a Rmd file with the 173 | required format.
    174 | When calling as an add-in: 175 | * if the call is done when the cursor is on a empty selection the user can 176 | enter also the number of rows and columns and the code to generate a empty 177 | tribble with the specified dimensions is also created; 178 | * if the call is done when the cursor is on a non-empty selection the user can 179 | only select the output format, and the add-in returns the code needed to 180 | create a table named as the selected text, with the specified format

    181 |

    When called as a function: 182 | * the code to generate a empty tribble with the specified dimensions is 183 | created (defaults are used if any parameter is not passed), followed by 184 | the code needed to create a table with the specified format. The results 185 | are sent back to the console.

    186 | 187 |

    Examples

    188 |
    if (FALSE) { 189 | # From the console, use: 190 | insert_table(nrows = 4, ncols = 3, tbl_format = "DT") 191 | 192 | # From a "Rmd" file and within RStudio, place the cursor on a empty line or 193 | # select the name a data.frame within a "R" chunk, then click on "Addins" 194 | # and select "Insert Table" 195 | }
    196 |
    197 | 208 |
    209 | 210 | 211 |
    212 | 215 | 216 |
    217 |

    Site built with pkgdown 1.4.1.

    218 |
    219 | 220 |
    221 |
    222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /docs/sitemap.txt: -------------------------------------------------------------------------------- 1 | http://lbusett.github.io/insert_table/reference/insert_table.html 2 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | https://lbusett.github.io/insert_table//index.html 5 | 6 | 7 | https://lbusett.github.io/insert_table//reference/get_table_code.html 8 | 9 | 10 | https://lbusett.github.io/insert_table//reference/insert_table.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /insert_table.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /inserttable.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | addin 2 | Addin 3 | Addins 4 | DT 5 | etcetera 6 | gmail 7 | kable 8 | kableExtra 9 | lbusett 10 | McBain's 11 | McBain’s 12 | ncols 13 | phantomjs 14 | phD 15 | rhandsontable 16 | RMarkdown 17 | Rmd 18 | RStudio 19 | tibble 20 | tribble 21 | yaml 22 | -------------------------------------------------------------------------------- /inst/rstudio/addins.dcf: -------------------------------------------------------------------------------- 1 | Name: Insert Table 2 | Description: Insert table into a blog post. 3 | Binding: insert_table 4 | Interactive: true 5 | -------------------------------------------------------------------------------- /man/figures/animation_1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/man/figures/animation_1.gif -------------------------------------------------------------------------------- /man/figures/animation_2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/man/figures/animation_2.gif -------------------------------------------------------------------------------- /man/figures/animation_3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/man/figures/animation_3.gif -------------------------------------------------------------------------------- /man/figures/animation_4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/man/figures/animation_4.gif -------------------------------------------------------------------------------- /man/figures/insert-table.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/man/figures/logo.png -------------------------------------------------------------------------------- /man/get_table_code.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_table_code.R 3 | \name{get_table_code} 4 | \alias{get_table_code} 5 | \title{get_table_code} 6 | \usage{ 7 | get_table_code(out_tbl, is_console, context) 8 | } 9 | \arguments{ 10 | \item{out_tbl}{`list` passed from `insert_table` and containing 4 elements: 11 | 1: data.frame to be used to generate the table, 2: context of the call, 12 | 3: column names (optional) and 4: table name} 13 | 14 | \item{is_console}{`logical` if TRUE, the insert_table function was called 15 | from the console, otherwise from an Rmd file using the addin} 16 | 17 | \item{context}{context of the call (tells if from console or file, and if 18 | from file allows to retrieve the lines, etcetera)} 19 | } 20 | \value{ 21 | returns the code needed to generate the table, either by creating 22 | new lines in the Rmd, or by printing it to the console (if is.console = TRUE) 23 | } 24 | \description{ 25 | Accessory function used to generate the code needed to generate 26 | the table in the selected output format 27 | } 28 | \author{ 29 | Lorenzo Busetto, phD (2017) 30 | } 31 | -------------------------------------------------------------------------------- /man/insert_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/insert_table.R 3 | \name{insert_table} 4 | \alias{insert_table} 5 | \title{insert_table} 6 | \usage{ 7 | insert_table(nrows = 3, ncols = 3, tbl_format = "kable", 8 | tbl_name = "my_tbl", colnames = NULL) 9 | } 10 | \arguments{ 11 | \item{nrows}{`numeric` number of rows of the generated empty table, Default: 1 12 | (ignored if calling the addin from an empty Rmd line)} 13 | 14 | \item{ncols}{`numeric` number of columns of the generated empty table, Default: 1 15 | (ignored if calling the addin from an empty Rmd line)} 16 | 17 | \item{tbl_format}{`character` [`kable` | `kableExtra - html` | `kableExtra - pdf` | 18 | `DT` | `rhandsontable` | `None`] format 19 | required for the table to be created (ignored if calling as an addin)} 20 | 21 | \item{tbl_name}{`character` name required for the table to be created 22 | (ignored if calling as an addin)} 23 | 24 | \item{colnames}{`character` of length ncols containing the desired column names 25 | (ignored if calling as an addin)} 26 | } 27 | \value{ 28 | returns the code required to create a table in a Rmd file with the 29 | required format. \cr 30 | When calling as an add-in: 31 | * if the call is done when the cursor is on a empty selection the user can 32 | enter also the number of rows and columns and the code to generate a empty 33 | tribble with the specified dimensions is also created; 34 | * if the call is done when the cursor is on a non-empty selection the user can 35 | only select the output format, and the add-in returns the code needed to 36 | create a table named as the selected text, with the specified format 37 | 38 | When called as a function: 39 | * the code to generate a empty tribble with the specified dimensions is 40 | created (defaults are used if any parameter is not passed), followed by 41 | the code needed to create a table with the specified format. The results 42 | are sent back to the console. 43 | } 44 | \description{ 45 | Function and RStudio add-in allowing to quickly and automatically 46 | generate the code needed to render a table in a RMarkdown document using different 47 | formats (kable, kableExtra, DT and rhandsontable are currently implemented - if "None" 48 | is selected only the code to generate a new tibble with the provided content 49 | is provided). 50 | } 51 | \examples{ 52 | \dontrun{ 53 | # From the console, use: 54 | insert_table(nrows = 4, ncols = 3, tbl_format = "DT") 55 | 56 | # From a "Rmd" file and within RStudio, place the cursor on a empty line or 57 | # select the name a data.frame within a "R" chunk, then click on "Addins" 58 | # and select "Insert Table" 59 | } 60 | } 61 | \author{ 62 | Lorenzo Busetto, phD (2017) 63 | } 64 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbusett/insert_table/034080d9138b6afbf09af32593d850614dae79b7/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if(requireNamespace('spelling', quietly = TRUE)) 2 | spelling::spell_check_test(vignettes = TRUE, error = FALSE, 3 | skip_on_cran = TRUE) 4 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | --------------------------------------------------------------------------------