内容:

统计文件

  • 版本 :2022.1 及更高版本

本文介绍如何将 Tableau 连接到统计文件并设置数据源。

Tableau 连接到 SAS (*.sas7bdat)、SPSS (*.sav) 和 R (*.rdata, *.rda) 数据文件。

注意:从版本 2020.1 开始,Tableau 不再支持使用 SASYZCR2 压缩的统计文件。使用不同的压缩方案使文件对 Tableau 可读。

建立连接并设置数据源

  1. 启动 Tableau,在“连接”下,选择“统计文件”,选择要连接到的文件,然后选择“打开”。

  2. 在数据源页面上,执行以下操作:

    1. (可选)选择页面顶部的默认数据源名称,然后输入要在 Tableau 中使用的唯一数据源名称。例如,使用数据源命名约定,帮助数据源的其他用户确定要连接到哪个数据源。

    2. 选择工作表选项卡以开始分析。

      有关连接到多个表的信息,请参阅联接数据

统计文件数据源示例

下面是在 Windows 计算机上使用 Tableau Desktop 的统计文件数据源的示例:

请注意以下几点:

  • 统计文件连接器不支持值标签。

  • 统计文件连接器仅支持每个统计文件一个表。

    如果出现错误消息“与数据源通信时出错”,请确保您的统计文件仅包含一个对象,并且该对象是数据框或矩阵。R 文件可能包含隐藏对象,这些对象似乎是干净的工作区。要检查隐藏的对象,请从 RStudio 运行。ls(environment(), all.names=TRUE)

  • 您可以更改统计文件的字符编码。有关详细信息,请参阅更改统计文件的字符编码

R 数据文件对象和格式支持

R 数据文件应仅包含以下类型的对象之一:

  • 二维矩阵

  • 向量

  • Factors

  • Data frames

Note that if the R data file contains more than one object, Tableau will connect to the first one.

Tableau supports R data files that use binary format.

ASCII format files are not supported in Tableau Desktop. If you try to use an .rdata or .rda file with ASCII format, you’ll see an error saying, "Unable to read from file the table '' '[TableauTemp].[filename.rdata]' does not exist". In this case, you can use RStudio to save the file to a binary format, as follows:

  1. Download RStudio if you don’t already have it.

  2. Open your R data file in RStudio. You should see your data object in the global environment window on the upper right.

  3. Save the object to a new file with the "save()" function as follows:

    save(

    where:

    Tip: To quickly see documentation for this function, type "?save" at the command prompt.

Compressed files are not supported in Tableau Desktop. You must decompress files first with another program, such as Gzip or WinZip, before you connect with Tableau.

Change the character encoding for a statistical file

Tableau reads the data in a statistical file (for example, an SAS or R file) based on the file's character encoding or on information in an input file. R files typically use the character encoding of the operating system, compared to SAS and SPSS files, which include the character encoding information in the file. Sometimes, you might need to specify a different encoding. For example, if a colleague sends you a statistical file with Greek character encoding, then you must specify a Greek character set to use the file with Tableau. If you need to use a different character set when reading from a statistical file, you can create a Tableau data source customization (TDC) file and specify the encoding to use.

Create the TDC file

A .tdc file is an XML file that applies to a single data source and contains vendor and driver name information of the data source provider. For the statistical file connector, the vendor and driver name is .stat-direct

To create a TDC file:

  1. Open a plain text editor, such as Notepad.

  2. Copy the information from the sample provided below, paste it into your text file, and then specify the value. (For a list of encodings, see User-defined Encodings Supported by the Statistical File Connector.)source-charset

  3. Save the file with a .tdc extension—for example, —to the My Tableau Repository\Datasources folder.r-statsfile.tdc

Sample TDC file sets the source-charset value

The following TDC file example sets the value to for a statistical file data source.source-charsetshift-jis

connection-customization class='stat-direct' enabled='true' version='10.0'>vendor name='stat-direct' />driver name='stat-direct' />
  customizations>
    customization name='source-charset' value='shift-jis' />
  customizations>connection-customization>

Important: Tableau does not test or support TDC files. These files should be used as a tool to explore or occasionally address issues with your data connection. Creating and maintaining TDC files requires careful manual editing, and there is no support for sharing these files.

About .ttde and .hhyper files

在浏览计算机目录时,您可能会注意到 .ttde 或 .hhyper 文件。创建连接到数据的 Tableau 数据源时,Tableau 会创建一个 .ttde 或 .hhyper 文件。此文件也称为卷影数据提取,用于帮助提高数据源在 Tableau Desktop 中的加载速度。尽管影子数据提取包含与标准 Tableau 数据提取类似的基础数据和其他信息,但影子数据提取以不同的格式保存,不能用于恢复数据。

在某些情况下,您可能需要从计算机中删除影子数据提取。有关详细信息,请参阅 Tableau 知识库中的由于影子提取而导致的磁盘空间不足

另请参见

本节中的其他文章