Skip to content

Commit

Permalink
Add write_xlsx() function (closes #45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiromagno committed Dec 14, 2023
1 parent dccccd0 commit 9e82eb8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Imports:
plyr,
testthat,
utils,
progress
progress,
writexl
Suggests:
httptest,
spelling,
Expand Down Expand Up @@ -85,5 +86,6 @@ Collate:
'tests.R'
'utils-pipe.R'
'utils.R'
'write_xlsx.R'
VignetteBuilder: knitr
biocViews: ThirdPartyClient, BiomedicalInformatics, GenomeWideAssociation, SNP
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export(union)
export(variant_to_association)
export(variant_to_study)
export(variant_to_trait)
export(write_xlsx)
exportClasses(associations)
exportClasses(studies)
exportClasses(traits)
Expand Down
28 changes: 28 additions & 0 deletions R/write_xlsx.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#' Export a GWAS Catalog object to xlsx
#'
#' This function exports a GWAS Catalog object to Microsoft Excel xlsx file.
#' Each table (slot) is saved in its own sheet.
#'
#' @param x A \linkS4class{studies}, \linkS4class{associations},
#' \linkS4class{variants} or \linkS4class{traits} object.
#' @param file A file name to write to.
#'
#' @return Although this function is run for its side effect of writing an xlsx
#' file, the path to the exported file is returned.
#'
#' @examples
#' # Initial setup
#' .old_wd <- setwd(tempdir())
#'
#' # Save an `associations` object, e.g. `associations_ex01`, to xlsx.
#' write_xlsx(associations_ex01, "associations.xlsx")
#'
#' # Cleanup
#' unlink("associations.xlsx")
#' setwd(.old_wd)
#'
#' @export
write_xlsx <- function(x, file = stop('`file` must be specified')) {
lst <- s4_to_list(x)
writexl::write_xlsx(lst, path = file)
}
3 changes: 3 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ Magno's
ABHD
pkgdown
precompiled
fns
png
xlsx
34 changes: 34 additions & 0 deletions man/write_xlsx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e82eb8

Please sign in to comment.