From kwright68 at gmail.com  Mon Nov 21 18:13:36 2005
From: kwright68 at gmail.com (kwright68@gmail.com)
Date: Mon, 21 Nov 2005 18:13:36 +0100 (CET)
Subject: [Rd] formatC adds leading space to exponential format (PR#8337)
Message-ID: <20051121171336.1A1698565@slim.kubism.ku.dk>

Full_Name: Kevin Wright
Version: 2.2.0
OS: Windows 2000
Submission from: (NULL) (170.54.58.4)



Apologies if my expectations (or reading of the man page) are incorrect.  

I seem unable to left-justify exponential format numbers.  There appears to
always be an extra space inserted to the left.

Using the example from the formatC help page:

R> xx  <- pi * 10^(-5:4)

R> cbind(formatC(xx, wid = 9, flag = "-"))
      [,1]        
 [1,] " 3.142e-05"
 [2,] "0.0003142" 
 [3,] "0.003142 " 
 [4,] "0.03142  " 
 [5,] "0.3142   " 
 [6,] "3.142    " 
 [7,] "31.42    " 
 [8,] "314.2    " 
 [9,] "3142     " 
[10,] " 3.142e+04"


# What does R want to do by default?
# Exponential numbers have a leading space

R> formatC(xx)
 [1] " 3.142e-05" "0.0003142"  "0.003142"   "0.03142"    "0.3142"    
 [6] "3.142"      "31.42"      "314.2"      "3142"       " 3.142e+04"


# Maybe space is reserved for a +/- sign?  Let's try formatting negative
numbers
# Still an extra space before exponential numbers

R> cbind(formatC(-xx, wid = 9, flag = "-"))
      [,1]         
 [1,] " -3.142e-05"
 [2,] "-0.0003142" 
 [3,] "-0.003142"  
 [4,] "-0.03142 "  
 [5,] "-0.3142  "  
 [6,] "-3.142   "  
 [7,] "-31.42   "  
 [8,] "-314.2   "  
 [9,] "-3142    "  
[10,] " -3.142e+04"

# Try to force left-justification using 'width=-1',
# still no luck.

R> cbind(formatC(xx, wid = -1))
      [,1]        
 [1,] " 3.142e-05"
 [2,] "0.0003142" 
 [3,] "0.003142"  
 [4,] "0.03142"   
 [5,] "0.3142"    
 [6,] "3.142"     
 [7,] "31.42"     
 [8,] "314.2"     
 [9,] "3142"      
[10,] " 3.142e+04"



[Rd] formatC adds leading space to exponential format (PR#8337)
kwright68@gmail.com