2014-06-10 4 views
5

Je créerais un fichier tar.gz à partir de R. Mais la fonction tar ne me fonctionne pas. Ceci est mon code d'exemple.Comment créer un fichier tar.gz dans R?

writeLines('aaaa', 'tmp.txt') 
tar('tmp.tar.gz', 'tmp.txt', compression = 'gzip') 

Ce code crée un tmp.tar.gz, mais tmp.txt ne comprend pas dans le fichier gz.

Y a-t-il des erreurs dans mon code?

Merci pour vos suggestions.

J'exécuter ce code sous Windows et 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 

Répondre

9

Je suppose que vous n'avez défini la variable d'environnement "tar". L'argument par défaut de tar() appelé tar est défini par un appel à Sys.getenv("tar"). S'il s'agit d'une chaîne vide, alors le tar interne de R est utilisé (cela ne fonctionne pas non plus sur mon système).

Ainsi, vous pouvez soit Sys.setenv la variable "tar", ou de fournir le nom de la commande tar externe/chemin manuellement:

tar('tmp.tar.gz', 'tmp.txt', compression = 'gzip', tar="tar") 
+1

Merci pour votre réponse. J'ai une chaîne vide ("") lorsque j'appelle Sys.getenv ("tar") sous linux. – Bangyou

+1

Merci pour vos suggestions. ça fonctionne maintenant. – Bangyou

+0

Bonjour, j'ai essayé de définir ma variable tar avec Sys.setenv (tar = "pathToTarCmd"), cela semble fonctionner parce que je le vérifie avec Sys.getenv ("tar") qui retourne une chaîne non nulle mais quand j'appelle la commande tar comme vous le faites, ça ne marche pas, comment puis-je le faire? – HanniBaL90

Questions connexes