找回密码
 注册
查看: 3111|回复: 0

R语言:connections()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 19:50:52 | 显示全部楼层 |阅读模式
connections(base)
connections()所属R语言包:base

                                        Functions to Manipulate Connections
                                         功能来操纵连接

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Functions to create, open and close connections.
功能来创建,打开和关闭连接。


用法----------Usage----------


file(description = "", open = "", blocking = TRUE,
     encoding = getOption("encoding"), raw = FALSE)

url(description, open = "", blocking = TRUE,
    encoding = getOption("encoding"))

gzfile(description, open = "", encoding = getOption("encoding"),
       compression = 6)

bzfile(description, open = "", encoding = getOption("encoding"),
       compression = 9)

xzfile(description, open = "", encoding = getOption("encoding"),
       compression = 6)

unz(description, filename, open = "",
    encoding = getOption("encoding"))

pipe(description, open = "", encoding = getOption("encoding"))

fifo(description, open = "", blocking = FALSE,
     encoding = getOption("encoding"))

socketConnection(host = "localhost", port, server = FALSE,
                 blocking = FALSE, open = "a+",
                 encoding = getOption("encoding"),
                 timeout = getOption("timeout"))

open(con, ...)
## S3 method for class 'connection'
open(con, open = "r", blocking = TRUE, ...)

close(con, ...)
## S3 method for class 'connection'
close(con, type = "rw", ...)

flush(con)

isOpen(con, rw = "")
isIncomplete(con)



参数----------Arguments----------

参数:description
character string.  A description of the connection: see "Details".
字符串。连接的描述:“详细资料”。


参数:open
character.  A description of how to open the connection (if it should be opened initially).  See section "Modes" for possible values.
字符。一个描述如何打开连接(如果最初应打开)。可能的值,见一节“模式”。


参数:blocking
logical.  See the "Blocking" section.
逻辑。看到堵节。


参数:encoding
The name of the encoding to be used.  See the "Encoding" section.
要使用的编码名称。看到“编码”一节。


参数:raw
logical.  If true, a "raw" interface is used which will be more suitable for arguments which are not regular files, e.g. character devices.  This suppresses the check for a compressed file when opening for text-mode reading, and asserts that the "file" may not be seekable.
逻辑。如果情况属实,这将是更适合的论据是不是普通的文件,如“原始”接口用于字符设备。这抑制检查压缩文件的文本模式阅读时开放,并声称,“文件”未必可查找。


参数:compression
integer in 0–9.  The amount of compression to be applied when writing, from none to maximal available.  For xzfile can also be negative: see the "Compression" section.
整数0-9。写作时,从没有到最大可被应用的压缩量。 xzfile也可以是负面的:看到“压缩”一节。


参数:timeout
numeric: the timeout (in seconds) to be used for this connection.  Beware that some OSes may treat very large values as zero: however the POSIX standard requires values up to 31 days to be supported.
数字:被用于此连接的超时(秒)。当心,有些操作系统可能非常大的值当作零:但是POSIX标准要求值高达31天予以支持。


参数:filename
a filename within a zip file.
在一个zip文件的文件名。


参数:host
character.  Host name for port.
字符。主机端口的名称。


参数:port
integer.  The TCP port number.
整数。 TCP端口号。


参数:server
logical.  Should the socket be a client or a server?
逻辑。插座应是一个客户端或服务器?


参数:con
a connection.
一个连接。


参数:type
character.  Currently ignored.
字符。目前被忽略。


参数:rw
character.  Empty or "read" or "write", partial matches allowed.
字符。空或"read"或"write",允许部分匹配。


参数:...
arguments passed to or from other methods.
参数传递或其他方法。


Details

详情----------Details----------

The first nine functions create connections.  By default the connection is not opened (except for socketConnection), but may be opened by setting a non-empty value of argument open.
首九个月功能创建连接。默认情况下,未打开连接(除了socketConnection),但可以通过设置非空值的参数open打开。

For file the description is a path to the file to be opened or a complete URL (when it is the same as calling url), or "" (the default) or "clipboard" (see the "Clipboard" section).  Use "stdin" to refer to the C-level "standard input" of the process (which need not be connected to anything in a console or embedded version of R, and is not in RGui). See also stdin() for the subtly different R-level concept of stdin.
file的描述是一个要打开的文件的路径或一个完整的URL(当它是调用url),或""(默认)或<X >(见“剪贴板”部分)。使用"clipboard"C级的标准输入过程(不需要任何连接在控制台或嵌入式版本的R,"stdin")。也看到RGui微妙的不同概念的R级stdin()。

For url the description is a complete URL, including scheme (such as http://, ftp:// or file://).  Proxies can be specified for HTTP and FTP url connections: see download.file.
url的描述是一个完整的URL,包括计划(如http://,ftp://或file://)。可以指定HTTP和FTPurl连接代理:看到download.file。

For gzfile the description is the path to a file compressed by gzip: it can also open for reading uncompressed files and (as from R 2.10.0) those compressed by bzip2, xz or lzma.
对于gzfile的描述是压缩文件的路径gzip:它也可以打开读解压缩文件(2.10.0从R)bzip2压缩,xz或lzma。

For bzfile the description is the path to a file compressed by bzip2.
bzfile的描述是到bzip2压缩文件的路径。

For xzfile the description is the path to a file compressed by xz (http://en.wikipedia.org/wiki/Xz) or (for reading only) lzma (http://en.wikipedia.org/wiki/LZMA).
xzfile介绍xz(http://en.wikipedia.org/wiki/Xz)或(读)lzma(HTTP压缩文件的路径: / / en.wikipedia.org /维基/ LZMA压缩)。

unz reads (only) single files within zip files, in binary mode. The description is the full path to the zip file, with ".zip" extension if required.
unz读取(只)单个文件在zip文件以二进制模式。的描述是.zip扩展到zip文件的完整路径,如果需要的话。

For pipe the description is the command line to be piped to or from.  This is run in a shell, on Windows that specified by the COMSPEC environment variable.
pipe的描述是通过管道或从命令行。这是一个shell中运行,在Windows,COMSPEC环境变量指定的。

For fifo the description is the path of the fifo.  (Windows does not have fifos, so attempts to use this function there are an error.  It was possible to use file with fifos prior to R 2.10.0, but raw=TRUE is now required for reading, and fifo was always the documented interface.)
fifo介绍FIFO的路径。 (Windows不具有的FIFO,所以尝试使用此功能有一个错误,这是可能使用file的FIFO之前的R 2.10.0,但raw=TRUE现在需要阅读, fifo总是记录界面。)

All platforms support file, pipe, gzfile, bzfile, xzfile, unz and url("file://") connections.  The other connections may be partially implemented or not implemented at all.  (They do work on most Unix platforms, and all but fifo on Windows.)
所有平台都支持file,pipe,gzfile,bzfile,xzfile,unz和url("file://")连接。其他连接,可部分实施或不实施在所有。 (他们在大多数Unix平台上做工作,但fifoWindows上)。

The intention is that file and gzfile can be used generally for text input (from files and URLs) and binary input respectively.
其用意是file和gzfile一般可用于文本输入(从文件和URL)和二进制输入。

open, close and seek are generic functions: the following applies to the methods relevant to connections.
open,close和seek是通用功能:以下内容适用于有关连接的方法。

open opens a connection.  In general functions using connections will open them if they are not open, but then close them again, so to leave a connection open call open explicitly.
open打开一个连接。一般使用连接的功能,将打开他们,如果他们是不公开的,但然后再次关闭,所以留下一个连接调用open明确。

close closes and destroys a connection.  This will happen automatically in due course (with a warning) if there is no longer an R object referring to the connection.
close关闭和销毁一个连接。会出现这种情况自动在适当的时候(警告),如果有不再是指连接一个R对象。

A maximum of 128 connections can be allocated (not necessarily open) at any one time.  Three of these are pre-allocated (see stdout).   The OS will impose limits on the numbers of connections of various types, but these are usually larger than 125.
最多128个连接可以分配在任何一个时间(不一定是开放的)。这三个预分配(见stdout)。 OS将实行对不同类型的连接数的限制,但这些通常是超过125个。

flush flushes the output stream of a connection open for write/append (where implemented, currently for file and clipboard connections, stdout and stderr).
flush刷新写入/追加打开一个连接的输出流(在实施,目前文件和剪贴板连接,stdout和stderr)。

If for a file or fifo connection the description is "", the file/fifo is immediately opened (in "w+" mode unless open = "w+b" is specified) and unlinked from the file system.  This provides a temporary file/fifo to write to and then read from.
如果file或描述fifo连接"",文件/ FIFO立即打开("w+"模式,除非open = "w+b"指定的)和无关联从文件系统。这提供了一个临时文件/ FIFO写入和读取。


值----------Value----------

file, pipe, fifo, url, gzfile, bzfile, xzfile, unz and socketConnection return a connection object which inherits from class "connection" and has a first more specific class.
file,pipe,fifo,url,gzfile,bzfile,xzfile,unz和socketConnection返回一个连接对象继承自类"connection"第一个具体的类。

isOpen returns a logical value, whether the connection is currently open.
isOpen返回一个逻辑值,连接是否是目前开放。

isIncomplete returns a logical value, whether the last read attempt was blocked, or for an output text connection whether there is unflushed output.
isIncomplete返回一个逻辑值,最后一次读取的尝试是否被堵塞,或一个输出文本的连接是否有未刷新输出。


网址----------URLs----------

url and file support URL schemes http://, ftp:// and file://.
url和file支持的URL方案http://,ftp://和file://。

A note on file:// URLs.  The most general form (from RFC1738) is file://host/path/to/file, but R only accepts the form with an empty host field referring to the local machine. In this form the path is relative to the root of the filesystem, not a Windows concept.  The standard form is file:///d:/R/repos: for compatibility with earlier versions of R and Unix versions, any other form is parsed as R as file:// plus path_to_file. Also, backslashes are accepted within the path even though RFC1738 does not allow them.
对file://网址的说明。是最普遍的形式(RFC1738)file://host/path/to/file,但R只接受空host场的形式,指到本地机器。在这种形式下的路径是相对于根文件系统,而不是一个Windows的概念。标准形式是file:///d:/R/repos:R和Unix版本的早期版本的兼容性,任何其他形式为Rfile://加path_to_file解析。此外,反斜线内的路径被接受,即使RFC1738不允许他们。

No attempt is made to decode an encoded URL: call URLdecode if necessary.
没有尝试解码编码的URL:呼叫URLdecode如果有必要的。

Note that https:// connections are only supported if --internet2 or setInternet2(TRUE) was used (to make use of Internet Explorer internals), and then only if the certificate is considered to be valid.  With that option only, the http://user:pass@site notation for sites requiring authentication is also accepted.
注意只支持https://连接如果--internet2或setInternet2(TRUE)是使用(Internet Explorer的内部使用),然后只有当证书被认为是有效的。使用该选项,http://user:pass@site符号需要认证的网站也被接受。

Contributed package RCurl provides more comprehensive facilities to download from URLs.
贡献包RCurl提供更全面的设施,从URL下载。


模式----------Modes----------

Possible values for the argument open are
参数的可能值open




"r" or "rt" Open for reading in text mode.
"r"或"rt"在文本模式下打开阅读。




"w" or "wt" Open for writing in text mode.
"w"或"wt"写在文本模式下的开放。




"a" or "at" Open for appending in text mode.
"a"或"at"附加在文本模式下打开。




"rb" Open for reading in binary mode.
"rb"以二进制方式打开阅读。




"wb" Open for writing in binary mode.
"wb"写在二进制模式打开。




"ab" Open for appending in binary mode.
"ab"追加二进制模式打开。




"r+", "r+b" Open for reading and writing.
"r+","r+b"打开阅读和写作。




"w+", "w+b" Open for reading and writing,
"w+","w+b"打开阅读和写作,




"a+", "a+b" Open for reading and appending.
"a+","a+b"打开阅读和追加。

Not all modes are applicable to all connections: for example URLs can only be opened for reading.  Only file and socket connections can be opened for both reading and writing.  An unsupported mode is usually silently substituted.
并不是所有的模式是适用于所有连接:网址例如只能打开阅读。只有文件和套接字连接,可以打开阅读和写作。不支持的模式通常被静默取代。

For many connections there is little or no difference between text and binary modes.  For file-like connections on Windows, translation of line endings (between LF and CRLF) is done in text mode only (but text read operations on connections such as readLines, scan and source work for any form of line ending).  Various R operations are possible in only one of the modes: for example pushBack is text-oriented and is only allowed on connections open for reading in text mode, and binary operations such as readBin, load and save operations can only be done on binary-mode connections.
对于许多连接有很少或根本没有文本和二进制模式之间的差异。文件,就像在Windows行结尾的翻译(LF和CRLF的)连接仅在文本模式(但如readLinesscan和source连接文本阅读操作任何形式的行结束工作)。各种R行动是可能的模式只有一个:例如pushBack是面向文本的,并且只允许连接开放,在文本模式下阅读和二进制操作,如readBin,<X >和load操作只能在二进制模式连接。

The mode of a connection is determined when actually opened, which is deferred if open = "" is given (the default for all but socket connections).  An explicit call to open can specify the mode, but otherwise the mode will be "r".  (gzfile, bzfile and xzfile connections are exceptions, as the compressed file always has to be opened in binary mode and no conversion of line-endings is done even on Windows, so the default mode is interpreted as "rb".)  Most operations that need write access or text-only or binary-only mode will override the default mode of a non-yet-open connection.
连接模式确定实际打开时,如果open = ""(默认为所有,但套接字连接)而被推迟。显式调用open可以指定模式,但在其他的模式将是"r"。 (gzfile,bzfile和xzfile连接也有例外,压缩文件,始终要以二进制模式打开,并没有行结束转换完成后,即使在Windows,所以默认模式被解释为"rb")。大部分操作需要写访问或仅文本或二进制唯一模式,将覆盖非尚未打开的连接的默认模式。

Append modes need to be considered carefully for compressed-file connections.  They do <STRONG>not</STRONG> produce a single compressed stream on the file, but rather append a new compressed stream to the file. Readers (including R) may or may not read beyond end of the first stream: currently R does so for gzfile, bzfile and xzfile connections, but earlier versions did not.
追加模式需要仔细考虑压缩文件连接。他们不</ STRONG> <strong>不会产生一个单一文件压缩流,而是附加一个新的压缩文件流。读者(包括R)可能会或可能不会超越第一流的末尾读取:目前&#341;这样做gzfile,bzfile和xzfile连接,但没有早期版本。


压缩----------Compression----------

R has for a long time supported gzip and bzip2 compression, and support for xz compression (and read-only support for its precursor lzma compression) was added in R 2.10.0.
R有长期支持时间gzip和bzip2压缩,并支持xz压缩(其前身lzma压缩和只读支持)添加在R 2.10 .0。

For reading, the type of compression (if any) can be determined from the first few bytes of the file, and this is exploited as from R 2.10.0.  Thus for file(raw = FALSE) connections, if open is "", "r" or "rt" the connection can read any of the compressed file types as well as uncompressed files.  (Using "rb" will allow compressed files to be read byte-by-byte.) Similarly, gzfile connections can read any of the forms of compression and uncompressed files in any read mode.
阅读,压缩(如果有的话)的类型可确定的前几个字节的文件,这是剥削为从R 2.10.0。因此file(raw = FALSE)连接,如果open是"","r"或"rt"连接,可以读取任何的压缩文件类型,以及未压缩的文件。 (使用"rb"将允许压缩文件要读取的字节逐字节。)同样,gzfile连接可以读取压缩和未压缩的文件在任何只读模式的任何形式。

(The type of compression is determined when the connection is created if open is unspecified and a file of that name exists.  If the intention is to open the connection to write a file with a different form of compression under that name, specify open = "w" when the connection is created or unlink the file before creating the connection.)
(压缩型连接被创建时确定open如果是不确定的,该名称的文件存在,如果目的是要打开连接写一个与该名称下的不同形式的压缩文件,指定open = "w"创建连接时,或在建立连接之前unlink文件)。

For write-mode connections, compress specifies now hard the compressor works to minimize the file size, and higher values need more CPU time and more working memory (up to ca 800Mb for xzfile(compress = 9)).  For xzfile negative values of compress correspond to adding the xz argument -e: this takes more time (double?) to compress but may achieve (slightly) better compression.  The default (6) has good compression and modest (100Mb memory usage): but if you are using xz compression you are probably looking for high compression.
为写模式连接,compress指定现在很难压缩机工作,以尽量减少文件的大小和更高的价值,需要更多的CPU时间和更多的工作记忆(约800MBxzfile(compress = 9))。 xzfile负值compress对应加入xz说法-e:这需要更多的时间(双)压缩,但可能实现(略)更好的压缩。默认(6)具有良好的压缩和适中(100MB内存使用率),但如果你使用的是xz压缩你可能正在寻找高压缩。

Choosing the type of compression involves tradeoffs: gzip, bzip2 and xz are successively less widely supported, need more resources for both compression and decompression, and achieve more compression (although individual files may buck the general trend).  Typical experience is that bzip2 compression is 15% better on text files than gzip compression, and xz with maximal compression 30% better.  The experience with R save files is similar, but on some large ".rda" files xz compression is much better than the other two.  With current computers decompression times even with compress = 9 are typically modest and reading compressed files is usually faster than uncompressed ones because of the reduction in disc activity.
选择压缩类型涉及权衡:gzip,bzip2和xz先后较少的广泛支持,需要更多的资源压缩和解压,并实现更多的压缩(虽然个别文件可能逆势总的趋势)。典型经验是bzip2压缩15%,比gzip压缩文本文件,xz最大压缩30%。与R的经验save文件是相似的,但对一些大的.rda文件xz压缩比其他两个好很多。减压时间,即使目前电脑compress = 9通常是谦虚和读取压缩文件通常比未压缩的,因为光盘活动的减少速度更快。


编码----------Encoding----------

The encoding of the input/output stream of a connection can be specified by name in the same way as it would be given to iconv: see that help page for how to find out what encoding names are recognized on your platform.  Additionally, "" and "native.enc" both mean the "native" encoding, that is the internal encoding of the current locale and hence no translation is done.
连接的输入/输出流的编码可以以同样的方式在指定的名字,因为它会考虑iconv:如何找出什么样的编码名称确认您的平台上,帮助页面。此外,""和"native.enc"都意味着native的编码,这是当前语言环境的内部编码,因此没有翻译完成。

Re-encoding only works for connections in text mode: reading from a connection with re-encoding specified in binary mode will read the stream of bytes, but mixing text and binary mode reads (e.g. mixing calls to readLines and readChar) is likely to lead to incorrect results.
重新编码只能在文本模式下的连接:阅读与重新编码的二进制模式中指定的连接,将读取的字节流,但混合的文本和二进制模式读取(例如混合调用readLines和readChar)很可能会导致不正确的结果。

The encodings "UCS-2LE" and "UTF-16LE" are treated specially, as they are appropriate values for Windows "Unicode" text files.  If the first two bytes are the Byte Order Mark 0xFFFE then these are removed as some implementations of iconv do not accept BOMs.  Note that whereas most implementations will handle BOMs using encoding "UCS-2" and choose the appropriate byte order, some (including earlier versions of glibc) will not.  There is a subtle distinction between "UTF-16" and "UCS-2" (see http://en.wikipedia.org/wiki/UTF-16/UCS-2: the use of surrogate pairs is very rare so "UCS-2LE" is an appropriate first choice.
编码"UCS-2LE"和"UTF-16LE"特殊对待,因为它们是Windows的Unicode的文本文件的适当的值。如果前两个字节是字节顺序标记0xFFFE那么这些被删除一些iconv不接受的BOM实现。请注意,而大多数实现将使用编码"UCS-2"处理的BOM,并选择适当的字节顺序,一些(包括早期版本的glibc)不会。是"UTF-16"和"UCS-2"(见http://en.wikipedia.org/wiki/UTF-16/UCS-2之间微妙的区别:使用代理对是非常罕见的,所以"UCS-2LE"是一个合适的首选。

Requesting a conversion that is not supported is an error, reported when the connection is opened.  Exactly what happens when the requested translation cannot be done for invalid input is in general undocumented.  On output the result is likely to be that up to the error, with a warning.  On input, it will most likely be all or some of the input up to the error.
请求不被支持的转换,是一个错误,连接被打开时报告。究竟发生了什么不能做无效输入时所要求的翻译一般是无证。输出的结果很可能是错误的警告,。输入时,将最有可能全部或部分的输入错误。


阻塞----------Blocking----------

Whether or not the connection blocks can be specified for file, url (default yes) fifo and socket connections (default not).
连接块是否可以指定文件,URL(默认是)FIFO和插座的连接(默认)。

In blocking mode, functions using the connection do not return to the R evaluator until the read/write is complete.  In non-blocking mode, operations return as soon as possible, so on input they will return with whatever input is available (possibly none) and for output they will return whether or not the write succeeded.
在阻止模式下,使用连接的功能,不返回到R计算器,直到读/写操作完成。在非阻止模式下,操作返回尽快,所以输入上,他们将返回与任何可用的输入(可能没有)和输出,他们将返回是否写入成功。

The function readLines behaves differently in respect of incomplete last lines in the two modes: see its help page.
函数readLines表现不同的两种模式不完整的最后几行:看到它的帮助页面。

Even when a connection is in blocking mode, attempts are made to ensure that it does not block the event loop and hence the operation of GUI parts of R.  These do not always succeed, and the whole R process will be blocked during a DNS lookup on Unix, for example.
甚至当一个连接阻塞模式,尝试,以确保它不会阻止事件循环和R的GUI部分的运作,因此这些不总是成功,整个R进程将在DNS查找堵塞在Unix上,例如。

Most blocking operations on HTTP/FTP URLs and on sockets are subject to the timeout set by options("timeout").  Note that this is a timeout for no response, not for the whole operation.  The timeout is set at the time the connection is opened (more precisely, when the last connection of that type &ndash; http:, ftp: or socket &ndash; was opened).
大多数阻塞HTTP / FTP的URL和插座的操作超时设置options("timeout")。请注意,这是一个没有响应超时,而不是为整个操作。超时设置在连接打开的时间(更确切地说,当该类型的最后一个连接 - http:,ftp:或插座 - 打开)。


FIFO的----------Fifos----------

Fifos default to non-blocking.  That follows S version 4 and is probably most natural, but it does have some implications.  In particular, opening a non-blocking fifo connection for writing (only) will fail unless some other process is reading on the fifo.
非阻塞FIFO的默认。这是继S版4,可能是最自然的,但它确实有一些影响。尤其是开放为书面形式(只)会失败,除非一些其他进程正在读FIFO,非阻塞FIFO连接。

Opening a fifo for both reading and writing (in any mode: one can only append to fifos) connects both sides of the fifo to the R process, and provides an similar facility to file().
开放阅读和写作的FIFO(在任何模式下只能追加到FIFO的)FIFO的双方连接到R进程,并提供了一个类似的设施file()。


剪贴板----------Clipboard----------

file can be used with description = "clipboard" in modes "r" and "w" only.
file可以用description = "clipboard"模式"r"和"w"。

When a clipboard is opened for reading, the contents are immediately copied to internal storage in the connection.
当剪贴板为读而打开,立即复制的内容连接到内部存储。

When writing to the clipboard, the output is copied to the clipboard only when the connection is closed or flushed.  There is a 32Kb limit on the text to be written to the clipboard.  This can be raised by using e.g. file("clipboard-128") to give 128Kb.
当写入到剪贴板,输出复制到剪贴板只有当连接被关闭或刷新。被写入到剪贴板的文本上有一个32KB的限制。这可以提高使用例如file("clipboard-128")给128KB。

The clipboard works in Unicode wide characters, so encodings might not work as one might expect.
剪贴板Unicode宽字符,这样编码可能无法正常工作正如人们所预料。


注意----------Note----------

R's connections are modelled on those in S version 4 (see Chambers, 1998).  However R goes well beyond the S model, for example in output text connections and URL, compressed and socket connections.
R的连接在S版本4(见钱伯斯,1998年)为蓝本。然而&#341;远远超出S模式,例如在输出文本连接和URL,压缩和套接字连接。

The default open mode in R is "r" except for socket connections. This differs from S, where it is the equivalent of "r+", known as "*".
在R打开默认的模式是"r"除了套接字连接。此不同,它是相当于"r+""*"众所周知,从S。

On (rare) platforms where vsnprintf does not return the needed length of output there is a 100,000 byte output limit on the length of line for text output on fifo, gzfile, bzfile and xzfile connections: longer lines will be truncated with a warning.
(罕见)平台vsnprintf不返回所需长度的输出有输出线长度100,000字节限制文本输出fifo,gzfile,<X >和bzfile连接:更长的线将被截断警告。


参考文献----------References----------

Programming with Data.  A Guide to the S Language. Springer.
http://www.r-project.org/doc/Rnews/Rnews_2001-1.pdf

参见----------See Also----------

textConnection, seek, showConnections, pushBack.
textConnection,seek,showConnections,pushBack。

Functions making direct use of connections are (text-mode) readLines, writeLines, cat, sink, scan, parse, read.dcf, dput, dump and (binary-mode) readBin, readChar, writeBin, writeChar, load and save.
使直接连接使用的功能(文本模式)readLines,writeLines,cat,sink,scan,parse,< x>,read.dcf,dput“(二进制模式)dump,readBin,readChar,writeBin,writeChar load。

capabilities to see if HTTP/FTP url, fifo and socketConnection are supported by this build of R.
capabilities看到,如果是HTTP / FTP url,fifo和socketConnection支持这个R的构建

gzcon to wrap gzip (de)compression around a connection.
gzcon包装gzip(德)压缩周围的连接。

memCompress for more ways to (de)compress and references on data compression.
memCompress(德)压缩和引用数据压缩更多的途径。

To flush output to the console, see flush.console.
要刷新输出到控制台,看到flush.console。


举例----------Examples----------


zz &lt;- file("ex.data", "w")  # open an output file connection[打开一个输出文件中的连接]
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")
cat("One more line\n", file = zz)
close(zz)
readLines("ex.data")
unlink("ex.data")

zz &lt;- gzfile("ex.gz", "w")  # compressed file[压缩文件]
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")
close(zz)
readLines(zz <- gzfile("ex.gz"))
close(zz)
unlink("ex.gz")

zz &lt;- bzfile("ex.bz2", "w")  # bzip2-ed file[bzip2压缩的编文件]
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")
close(zz)
print(readLines(zz <- bzfile("ex.bz2")))
close(zz)
unlink("ex.bz2")

## An example of a file open for reading and writing[#例如一个文件打开阅读和写作]
Tfile <- file("test1", "w+")
c(isOpen(Tfile, "r"), isOpen(Tfile, "w")) # both TRUE[双方真实]
cat("abc\ndef\n", file=Tfile)
readLines(Tfile)
seek(Tfile, 0, rw="r") # reset to beginning[复位开始]
readLines(Tfile)
cat("ghi\n", file=Tfile)
readLines(Tfile)
close(Tfile)
unlink("test1")

## We can do the same thing with an anonymous file.[#我们可以做同样的事情,一个匿名文件。]
Tfile <- file()
cat("abc\ndef\n", file=Tfile)
readLines(Tfile)
close(Tfile)

## fifo example -- may fail even with OS support for fifos[#FIFO例子 - 可能失败,即使与FIFO的操作系统支持]
if(capabilities("fifo")) {
  zz <- fifo("foo-fifo", "w+")
  writeLines("abc", zz)
  print(readLines(zz))
  close(zz)
  unlink("foo-fifo")
}

## Not run: [#无法运行:]
## Two R processes communicating via non-blocking sockets[#2枚R通过非阻塞套接字通信的进程]
# R process 1[R过程1]
con1 <- socketConnection(port = 6011, server=TRUE)
writeLines(LETTERS, con1)
close(con1)

# R process 2[R过程2]
con2 <- socketConnection(Sys.info()["nodename"], port = 6011)
# as non-blocking, may need to loop for input[非阻断,可能需要输入的循环]
readLines(con2)
while(isIncomplete(con2)) {Sys.sleep(1); readLines(con2)}
close(con2)

## examples of use of encodings[使用的编码#例子]
# write a file in UTF-8[写在UTF-8文件]
cat(x, file = (con <- file("foo", "w", encoding="UTF-8"))); close(con)
# read a 'Windows Unicode' file[阅读“的Windows Unicode的文件]
A <- read.table(con <- file("students", encoding="UCS-2LE")); close(con)


转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-24 21:17 , Processed in 0.022533 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表