WriteXLS(WriteXLS)
WriteXLS()所属R语言包:WriteXLS
Cross-platform Perl based R function to create Excel 2003 (XLS) files
跨平台的Perl为基础的R函数来创建Excel 2003文件(XLS)
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Writes one or more R data frames to an Excel 2003 file
将一个或多个R的数据框写入到Excel 2003文件
用法----------Usage----------
WriteXLS(x, ExcelFileName = "R.xls", SheetNames = NULL, perl = "perl",
verbose = FALSE, Encoding = c("UTF-8", "latin1"),
row.names = FALSE,
AdjWidth = FALSE, AutoFilter = FALSE, BoldHeaderRow = FALSE,
FreezeRow = 0, FreezeCol = 0,
envir = parent.frame())
参数----------Arguments----------
参数:x
A character vector containing either the names of one or more R data frames, or the single name of a list containing one or more R data frames, to be exported to the Excel file.
一种字符向量,含有一个或多个R的数据框,或单一的名称的列表,其中包含一个或多个R的数据框中,将被导出到Excel文件的名称。
参数:ExcelFileName
The name of the Excel file to be created. Must be a valid Excel filename. May include an existing path.
要创建的Excel文件的名称。必须是一个有效的Excel文件名。可能包括现有的路径。
参数:SheetNames
A character vector containing the names of each worksheet to be created. If NULL (the default), the names of the dataframes will be used instead. Worksheet names may be up to 31 characters in length and must be unique. If specified, length(SheetNames) must be the same as length(x). NOTE: The order of the names here must match the order of the data frames as listed in x.
要创建一个字符向量,其中包含每个工作表的名称。如果NULL(默认值),在dataframes的名字将被用来代替。工作表名称可长达31个字符的长度必须是唯一的。如果指定的话,length(SheetNames)必须是一样length(x)。注:这里的名字的顺序必须的顺序相匹配的数据框中列出的x。
参数:perl
Name of the perl executable to be called.
Perl的可执行文件的名称被调用。
参数:verbose
Output step-by-step status messages during the creation of the Excel file. Default is FALSE.
输出的Excel文件的创建过程中一步一步的状态消息。默认值是false。
参数:Encoding
Define the character encoding to be used for the exported data frames. Defaults to UTF-8.
用于导出的数据框定义的字符编码。默认为UTF-8的。
参数:row.names
If TRUE, the row names of the data frames are included in the Excel file worksheets.
如果TRUE,该行的数据框都包含在Excel文件中的工作表名。
参数:AdjWidth
If TRUE, will adjust the worksheet column widths based upon the longest entry in each column. This is approximate.
如果TRUE,将根据每列中的最长的项目调整工作表的列宽。这是近似的。
参数:AutoFilter
If TRUE, will add autofiltering to each column in each worksheet. Note that not all spreadsheet applications support this feature.
将增加如果TRUE,自动筛选到每个工作表中的每个列。请注意,并非所有的电子表格应用程序支持此功能。
参数:BoldHeaderRow
If TRUE, will apply a bold font to the header row for each worksheet.
如果TRUE,将适用于一个大胆的字体的每个工作表的标题行。
参数:FreezeRow
Rows including this row and above this row will be frozen and not scroll. The default value of 0 will scroll the entire sheet. Note that not all spreadsheet applications support this feature.
包括该行并高于此行的行会被冻结,而不是滚动。 0的默认值将滚动整个工作表。请注意,并非所有的电子表格应用程序支持此功能。
参数:FreezeCol
Columns including this column and to the left of this column will be frozen and not scroll. The default value of 0 will scroll the entire sheet. Note that not all spreadsheet applications support this feature.
包括此列,此列的左侧的列将被冻结,而不是滚动。 0的默认值将滚动整个工作表。请注意,并非所有的电子表格应用程序支持此功能。
参数:envir
The environment in which to look for the data frames named in x. This defaults to the environment in which WriteXLS was called.
环境在其中看数据框命名x。这是预设的环境中,WriteXLS被称为。
Details
详细信息----------Details----------
This function takes a character vector containing the names of one or more R data frames and writes them to an Excel 2003 spreadsheet file. Each data frame will be written to a separate worksheet in the Excel file.
这个函数接受一个字符向量,其中包含一个或多个R的数据框的名字,并把它们写入到Excel 2003电子表格文件。每个数据框都将被写入到一个单独的工作表的Excel文件中。
The order of the worksheets created in the Excel file will match the order of the entries in x.
在Excel文件中创建的工作表的顺序的顺序相匹配的条目在x。
The actual creation of the Excel file is performed by a Perl script called WriteXLS.pl, which is included with this package.
实际创建的Excel文件是由一个Perl脚本称为WriteXLS.pl,它包含在这个包。
Note that the named Excel file, if it already exists, will be overwritten and no warning is given. In addition, if the file exists and is open by another application (eg. Excel, OO.org, etc.) you will likely get an error message regarding the inability to open the file and/or that the file is already in use by another application or user. Errors can also occur if the file has been marked as read-only or if your access rights do not allow you to overwrite the file or write to the folder you have indicated in the path to the file.
请注意,命名的Excel文件,如果它已经存在,将被覆盖,并没有发出警告。此外,如果该文件存在并且是打开另一个应用程序(如Excel中,OO.org等),你可能会得到一个错误信息,就无法打开的文件和/或该文件已在使用中的另一个应用程序或用户。错误也可能发生,如果该文件被标记为只读,或者如果您的访问权限不允许覆盖文件或写入的文件夹都表示文件的路径。
There is an intermediate step, where the R data frames are first written to CSV files using write.table before being written to the Excel file by the Perl script. tempdir is used to determine the current R session temporary directory and a new sub-directory called "WriteXLS" will be created there. The CSV files will be written to that directory and both the files and the directory will be deleted prior to the function terminating normally using on.exit. It is possible that these will remain in place if this function terminates abnormally or is aborted prior to completion.
有一个中间步骤,其中R数据框首先被写入到CSV文件使用write.table然后再将其写入到Excel文件的Perl脚本。 tempdir是用来确定当前的的R会话临时目录,将创建一个新的子目录称为“WriteXLS”。 CSV文件将被写入到该目录中,这两个文件和目录将被删除的功能正常终止使用on.exit之前。这是可能的,这些将留在原地,如果这个功能异常终止或中止之前完成。
As write.table is used to write the data frames to CSV files, the data types supported by write.table will be exported to their character representation correctly. For other data types, it is recommended that you first coerce them to character columns formatted as you require and then use WriteXLS to create the Excel file.
write.table是用来写数据框到CSV文件,支持的数据类型write.table将出口到正确的字符表示。对于其它数据类型,建议您先强迫他们你需要的字符列格式化,然后使用WriteXLS创建的Excel文件。
All of the CSV files will be created prior to the creation of the Excel file as the Perl script will loop over them as part of the process. Thus, sufficient free disk space must be available for these files and the Excel file at the same time.
所有的CSV文件将被创建之前创建的Excel文件的Perl脚本将循环过程的一部分。因此,有足够的可用磁盘空间必须同时对这些文件和Excel文件。
A text file called "SheetNames.txt" will be created in the same temporary directory as the CSV files. This file will contain the sheet names, one per line and will be used by the Perl script to name the worksheets in the Excel file.
,将创建称为“SheetNames.txt”的一个文本文件,CSV文件在同一个临时目录。此文件将包含的工作表名称,每行一个,将被命名工作表的Excel文件中的Perl脚本。
Each worksheet will be named using either the names in SheetNames, the names of the data frames in x or the names of the list elements if x is a list (up to the first 31 characters, which is an Excel limitation). If any the data frame names specified in x are longer than 31 characters, they will be truncated to 31 characters. SheetNames if specified, will be checked to make sure that all of the entries are less than or equal to 31 characters. If not, an error message will be displayed.
使用中的名称,每个工作表将被命名为SheetNames“的数据框的名称x或名称的列表元素,如果x是一个列表(第31的字符,这是一个Excel的限制)。如果任何数据框中指定的名称x超过31个字符,他们将被截断为31个字符。 SheetNames:如果指定的话,将进行检查,以确保所有的条目都小于或等于31个字符。如果不是,错误信息将被显示。
Note that the order of the names in SheetNames MUST match the order of the data frames named in x.
请注意,在SheetNames的名字的顺序必须匹配的数据框的顺序命名x。
Note that the worksheets must have unique names. Thus, if SheetNames is NULL, the data frame names will be checked to be sure that they are unique up through the first 31 characters. If SheetNames is specified, the entries will be checked to be sure that they are unique. If not, an error message will be displayed.
需要注意的是工作表的名称必须唯一。因此,如果SheetNames是NULL,数据框的名称进行检查,以确保它们是唯一通过前31个字符。如果SheetNames指定,参赛作品将进行检查,以确保它们是唯一的。如果不是,错误信息将被显示。
Note that the following characters are not allowed for Excel worksheet names: []:*?/\
请注意,下面的字符是不允许的Excel工作表名称:[] * / \
The data frame column names will be exported "as is" and will be the first row in the corresponding worksheet.
将出口“是”,将相应的工作表中的第一行数据框的列名。
UTF-8 encoded content in the data frame should be properly exported using the Perl Encode module by default. If you are operating in a 'latin1' based locale (also known as iso-8859-1), set Encoding to 'latin1'.
UTF-8编码的数据框中的内容应被正确地导出使用的Perl Encode模块的默认。如果您正在运行的“基于拉丁文的语言环境(也称为ISO-8859-1),设置Encoding为”latin1的“。
Note that arguments AdjWidth, AutoFilter, BoldHeaderRow, FreezeRow and FreezeCol will apply to ALL worksheets exported.
请注意,参数AdjWidth,AutoFilter,BoldHeaderRow,FreezeRow和FreezeCol将适用于所有的工作表出口。
值----------Value----------
TRUE if the Excel file was successfully created. FALSE if any errors occurred.
TRUE如果Excel文件已成功创建。 FALSE如果发生任何错误。
注意----------Note----------
Please be sure to read the included INSTALL file (in the main package installation directory) for additional details on meeting the requirements for Perl and the additional Perl modules that are necessary for this function to work properly. The file includes platform specific recommendations for common scenarios. The path to the package installation directory can be located using .path.package("WriteXLS") after using library(WriteXLS).
请务必阅读附带的INSTALL文件(主包安装目录中)的要求Perl和机能得以正常工作所必需的额外的Perl模块的更多详细信息。该文件包含特定于平台的建议常见的情况。位于.path.package("WriteXLS")使用后library(WriteXLS)包的安装目录的路径。
A working installed version of Perl must be present in the current system searchpath or the exact path of the perl executable must be provided via the perl argument. Perl modules required for this function that may not be part of a default Perl installation are included with this package. These modules include:
一个工作版本的Perl安装在当前系统的搜索路径或Perl可执行文件的确切路径必须存在,必须通过perl参数。这个包所包含的Perl模块所需的功能,这可能不是一个默认的Perl安装的一部分。这些模块包括:
OLE::Storage_Lite, Parse::RecDescent, Getopt:ong, File::Basename and Spreadsheet::WriteExcel
OLE :: Storage_Lite,解析:: RecDescent的,长的Getopt ::文件:: basename和电子表格:: WriteExcel模块
Note that the required Perl modules Encode and Text::CSV_XS are not included with this package. They are platform specific, contain C source code requiring compilation and installation from CPAN or via your OS/Perl package manager to utilize pre-packaged binary versions.
请注意,所需的Perl模块编码和的文字:: CSV_XS是这个包不包括。他们是特定于平台的,包含C源代码需要从CPAN或通过OS / Perl包管理器,利用预先包装的二进制版本的编译和安装的。
To test your Perl installation and verify that all required Perl modules are available, use the testPerl function provided in this package.
要测试你的Perl安装,并确认所有需要的Perl模块,使用testPerl此包中提供的功能。
(作者)----------Author(s)----------
Marc Schwartz <a href="mailto:marc_schwartz@me.com">marc_schwartz@me.com</a>
Many thanks to Prof. Brian Ripley for his assistance in the testing of this package.
参考文献----------References----------
参见----------See Also----------
write.table and testPerl
write.table和testPerl
实例----------Examples----------
# Only run the examples if Perl and all modules are present[只有运行的例子,如果Perl和所有模块都存在]
if (testPerl(verbose = FALSE))
{
# Examples using built-in data frames [使用内置的例子在数据框]
WriteXLS("iris", "iris.xls")
WriteXLS(c("iris", "infert", "esoph"), "Example.xls")
iris.split <- split(iris, iris$Species)
WriteXLS("iris.split", "irissplit.xls")
# Clean up and delete XLS files[清理并删除XLS文件]
rm(iris.split)
unlink("iris.xls")
unlink("Example.xls")
unlink("irissplit.xls")
}
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|