2

Within R how could I try to use this unix command

printf "%s\t" NAMES n{1..1600} >file_o

Trying

system(paste("printf \"%s\t\" NAMES n{1..1600} >file_o"))

causes no message, but it does not create the same output. The file is just

NAMES   n{1..1600}

when it should be

NAMES n1 n2 (/t in betwen up to the max number )

the comments indicate that this might have somethign to do with the OS - on ubuntu it doesnt work neither on Debian

the output of printen

 [1] "LESSOPEN=| /usr/bin/lesspipe %s"                                                                                
 [2] "R_UNZIPCMD=/usr/bin/unzip"                                                                                      
 [3] "USER=katoui"                                                                                                   
 [4] "LANGUAGE=en_GB:en"                                                                                              
 [5] "UPSTART_INSTANCE="                                                                                              
 [6] "XDG_SEAT=seat0"                                                                                                 
 [7] "TEXTDOMAIN=im-config"                                                                                           
 [8] "SSH_AGENT_PID=1272"                                                                                             
 [9] "COMPIZ_CONFIG_PROFILE=ubuntu"                                                                                   
[10] "LD_LIBRARY_PATH=/usr/lib/R/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server"
[11] "SHLVL=1"                                                                                                        
[12] "HOME=/home/katou"                                                                                             
[13] "QT4_IM_MODULE=ibus"                                                                                             
[14] "DESKTOP_SESSION=ubuntu"                                                                                         
[15] "R_LIBS_SITE=/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"                           
[16] "GTK_MODULES=overlay-scrollbar:unity-gtk-module"                                                                 
[17] "XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0"                                                            
[18] "R_BROWSER=xdg-open"                                                                                             
[19] "PAGER=/usr/bin/pager"                                                                                           
[20] "INSTANCE=Unity"                                                                                                 
[21] "DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-hR5PKeEWoO"                                                    
[22] "R_SYSTEM_ABI=linux,gcc,gxx,gfortran,?"                                                                          
[23] "COLORTERM=gnome-terminal"                                                                                       
[24] "GNOME_KEYRING_CONTROL=/run/user/1000/keyring-FBpib0"                                                            
[25] "UBUNTU_MENUPROXY=1"                                                                                             
[26] "QT_QPA_PLATFORMTHEME=appmenu-qt5"                                                                               
[27] "MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path"                                                          
[28] "IM_CONFIG_PHASE=1"                                                                                              
[29] "SESSIONTYPE=gnome-session"                                                                                      
[30] "UPSTART_JOB=unity-settings-daemon"                                                                              
[31] "LOGNAME=katou"                                                                                                
[32] "GTK_IM_MODULE=ibus"                                                                                             
[33] "TAR=/bin/tar"                                                                                                   
[34] "WINDOWID=67112765"                                                                                              
[35] "DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path"                                                             
[36] "R_LIBS_USER=~/R/x86_64-pc-linux-gnu-library/3.1"                                                                
[37] "XDG_SESSION_ID=c1"                                                                                              
[38] "TERM=xterm"                                                                                                     
[39] "COLUMNS=80"                                                                                                     
[40] "GNOME_DESKTOP_SESSION_ID=this-is-deprecated"                                                                    
[41] "R_ARCH="                                                                                                        
[42] "R_PAPERSIZE_USER=a4"                                                                                            
[43] "PATH=/opt/texbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"      
[44] "SELINUX_INIT=YES"                                                                                               
[45] "GDM_LANG=en_GB"                                                                                                 
[46] "R_BZIPCMD=/bin/bzip2"                                                                                           
[47] "R_INCLUDE_DIR=/usr/share/R/include"                                                                             
[48] "XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0"                                                      
[49] "XDG_RUNTIME_DIR=/run/user/1000"                                                                                 
    [50] "R_SESSION_TMPDIR=/tmp/Rtmpg8bGY1"
51] "DISPLAY=:0"                                                                                                     
[52] "LANG=en_GB.UTF-8"                                                                                               
[53] "XDG_CURRENT_DESKTOP=Unity"                                                                                      
[54] "XMODIFIERS=@im=ibus"                                                                                            
[55] "XAUTHORITY=/home/maurice/.Xauthority"                                                                           
[56] "XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/maurice"                                                             
[57] "SSH_AGENT_LAUNCHER=upstart"                                                                                     
[58] "SSH_AUTH_SOCK=/run/user/1000/keyring-FBpib0/ssh"                                                                
[59] "R_GZIPCMD=/bin/gzip"                                                                                            
[60] "SED=/bin/sed"                                                                                                   
[61] "SHELL=/bin/bash"                                                                                                
[62] "LN_S=ln -s"                                                                                                     
[63] "QT_ACCESSIBILITY=1"                                                                                             
[64] "GDMSESSION=ubuntu"                                                                                              
[65] "R_PDFVIEWER=/usr/bin/xdg-open"                                                                                  
[66] "LESSCLOSE=/usr/bin/lesspipe %s %s"                                                                              
[67] "UPSTART_EVENTS=started starting"                                                                                
[68] "R_TEXI2DVICMD=/usr/bin/texi2dvi"                                                                                
[69] "GPG_AGENT_INFO=/run/user/1000/keyring-FBpib0/gpg:0:1"                                                           
[70] "UPSTART_SESSION=unix:abstract=/com/ubuntu/upstart-session/1000/1191"                                            
[71] "R_HOME=/usr/lib/R"                                                                                              
[72] "TEXTDOMAINDIR=/usr/share/locale/"                                                                               
[73] "R_PRINTCMD=/usr/bin/lpr"                                                                                        
[74] "XDG_VTNR=7"                                                                                                     
[75] "QT_IM_MODULE=ibus"                                                                                              
[76] "R_DOC_DIR=/usr/share/R/doc"                                                                                     
[77] "PWD=/home/ryo"                                                                                              
[78] "R_SHARE_DIR=/usr/share/R/share"                                                                                 
[79] "R_ZIPCMD=/usr/bin/zip"                                                                                          
[80] "CLUTTER_IM_MODULE=xim"                                                                                          
[81] "XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg"                                            
[82] "XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/"                                 
[83] "PYTHONPATH=:/usr/lib/python2.7/site-packages"                                                                   
[84] "R_PLATFORM=x86_64-pc-linux-gnu"                                                                                 
[85] "R_PAPERSIZE=letter"                                                                                             
[86] "LINES=24"                                                                                                       
[87] "MAKE=make"                                                                                                      
[88] "VTE_VERSION=3409"                                                                                               
[89] "R_RD4PDF=times,inconsolata,hyper"                                                                               
[90] "JOB=gnome-session"                                                                                              
[91] "EDITOR=vi"
15
  • Your code produced the expected result for me. What OS are you on? Are you sure your default shell is bash? If you fun system('printenv',intern=TRUE), what do you see listed under SHELL=? Commented Jul 5, 2015 at 5:24
  • Of course you could just create the file with R: writeLines(paste("NAMES",paste0("n", 1:1600, collapse=" ")), "file_o") Commented Jul 5, 2015 at 5:26
  • I am on bash yes...it is strange for me it doesnt work Commented Jul 5, 2015 at 5:33
  • @MrFlick for me this prodces a file with NAMES n{1..1600} ...the output i was looking for is NAMES tab n1 tab n2 tab n3 tab ....and that is the pont if i execute l the lien in bash Commented Jul 5, 2015 at 5:36
  • I do get the "NAMES\tn1\tn2\tn3..." values in the file. But I tested on my Mac. Again, it would be helpful to know the exact OS you are using and to see the output of system('printenv',intern=TRUE) on your system. Commented Jul 5, 2015 at 5:40

1 Answer 1

0

Two alternative ways to get the output are:

system('echo -n "NAMES\\\\t" > file_o') 

and

system(' for i in $(seq 0 1600)  ; do printf "n${i}\\\\t" >> file_o ; done')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.