I would create a tar.gz file from R. But the tar function doesn't work me. This is my example code.
我会从R创建一个tar.gz文件但是tar函数对我不起作用。这是我的示例代码。
writeLines('aaaa', 'tmp.txt')
tar('tmp.tar.gz', 'tmp.txt', compression = 'gzip')
This code creates a tmp.tar.gz, but tmp.txt doesn't include in the gz file.
此代码创建tmp.tar.gz,但tmp.txt不包含在gz文件中。
Are there any mistakes in my code?
我的代码中有错误吗?
Thanks for any suggestions.
谢谢你的任何建议。
I run this code in windows and linux:
我在windows和linux中运行此代码:
#Windows platform
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.1.0
#Linux platform
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C
[5] LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] weaana_0.1.0.3874 abind_1.4-0 reshape2_1.4 ncdf4cf_0.1.0.3698 ncdf4_1.10
[6] stringr_0.6.2 My_0.1.0.4086
loaded via a namespace (and not attached):
[1] Rcpp_0.11.1 plyr_1.8.1 tools_3.1.0
1 个解决方案
#1
10
I guess you do not have set the "tar"
environmental variable. The default argument of tar()
called tar
is set by a call to Sys.getenv("tar")
. If it is an empty string, then R's internal tar
is used (it doesn't work on my system either).
我猜你没有设置“tar”环境变量。调用tar的tar()的默认参数是通过调用Sys.getenv(“tar”)来设置的。如果它是一个空字符串,则使用R的内部tar(它在我的系统上也不起作用)。
So, you may either Sys.setenv
the "tar"
variable, or provide the name of external tar
command/path manually:
因此,您可以使用Sys.setenv“tar”变量,也可以手动提供外部tar命令/路径的名称:
tar('tmp.tar.gz', 'tmp.txt', compression = 'gzip', tar="tar")
#1
10
I guess you do not have set the "tar"
environmental variable. The default argument of tar()
called tar
is set by a call to Sys.getenv("tar")
. If it is an empty string, then R's internal tar
is used (it doesn't work on my system either).
我猜你没有设置“tar”环境变量。调用tar的tar()的默认参数是通过调用Sys.getenv(“tar”)来设置的。如果它是一个空字符串,则使用R的内部tar(它在我的系统上也不起作用)。
So, you may either Sys.setenv
the "tar"
variable, or provide the name of external tar
command/path manually:
因此,您可以使用Sys.setenv“tar”变量,也可以手动提供外部tar命令/路径的名称:
tar('tmp.tar.gz', 'tmp.txt', compression = 'gzip', tar="tar")