View source: R/make_dataframe_to_output.R
| make_dataframe_to_output | R Documentation |
If no output path is specified, the file is written to a temporary directory using 'tempdir()'. For reproducible workflows, users are encouraged to explicitly specify an output location, either the current working directory or a full file path.
make_dataframe_to_output(data, filename = NULL, format = "csv", path = NULL)
data |
A data frame to export. |
filename |
Optional base file name (without extension). Defaults to object name. (without path and without extension). If not provided, the name of the input object is used. |
format |
Character string specifying the output format. One of '"csv"', '"word"','"excel"' or '"pdf"'. Default is '"csv"'. |
path |
Optional character string specifying the directory where the file should be saved. If 'NULL' (default), the file is written to a temporary directory. Use 'path = getwd()' to save the file in the current working directory, or provide a full directory path. |
- CSV files are written using 'utils::write.csv()' - Word files ('docx') are created using the 'officer' package - Excel ('xlsx') files are created using the 'openxlsx' package - PDF files are created using the 'flextable' package
Invisibly returns the full file path to the generated output file.
Exporting to PDF requires the 'webshot2' package to be installed.
## Not run:
# Example dataset available in base R
data_df <- head(mtcars)
#--------------------------------------------------
# 1. Simplest use: export to CSV in temp directory
#--------------------------------------------------
make_dataframe_to_output(data_df)
#--------------------------------------------------
# 2. Specify filename
#--------------------------------------------------
make_dataframe_to_output(
data = data_df,
filename = "mtcars_sample"
)
#--------------------------------------------------
# 3. Export as Word document
#--------------------------------------------------
make_dataframe_to_output(
data = data_df,
filename = "mtcars_word_table",
format = "word"
)
#--------------------------------------------------
# 4. Export as Excel file
#--------------------------------------------------
make_dataframe_to_output(
data = data_df,
filename = "mtcars_excel_table",
format = "excel"
)
#--------------------------------------------------
# 5. Save to current working directory
#--------------------------------------------------
make_dataframe_to_output(
data = data_df,
filename = "mtcars_current_folder",
format = "csv",
path = "getwd()"
)
#--------------------------------------------------
# 6. Save Excel file to current working directory
#--------------------------------------------------
make_dataframe_to_output(
data = data_df,
filename = "mtcars_excel_current",
format = "excel",
path = "getwd()"
)
#--------------------------------------------------
# 7. Export another base dataset (iris)
#--------------------------------------------------
make_dataframe_to_output(
data = head(iris),
filename = "iris_sample",
format = "word"
)
#--------------------------------------------------
# 8. Using a custom folder path
#--------------------------------------------------
make_dataframe_to_output(
data = head(airquality),
filename = "airquality_data",
format = "excel",
path = "D:/output_folder"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.