Looks like you're loosing track of i vs i+1 in two places, the second while loop in ApproxRegion and the loop in ApproxSum. This looks like it works on your example:
ApproxRegion<-function(x,b,delta,n){
if(n<=1 || x[n]<b) return(NULL)
if(x[n-1]<b) return(c(n,n))
if(x[1]>=b) return(c(1,n))
m<-2
while(n-m**2>0 && x[n-m**2+1]>=b) m<-m**2
r<-m
while(m>=(1+delta)){
m<-sqrt(m)
if(n-floor(m*r)>=0 && x[n-floor(m*r)+1]>=b) r=m*r
}
return(c(n-floor(r)+1,n))
}
ApproxSum<-function(x,n,epsilon){
if(x[n]==0) return(0)
delta=3*epsilon/4
rp<-n
i<-0
s<-0
b<-x[n]/(1+delta)
while(b>=delta*x[n]/(3*n)){
R<-ApproxRegion(x,b,delta,rp)
if(is.null(R)) break
si<-(R[2]-R[1]+1)*b
s<-s+si
i<-i+1
rp<-R[1]-1;
b<-x[rp]/(1+delta)
}
return(list(s=s,i=i))
}
n<-100;
set.seed(123)
x<-sort(rexp(n));
eps<-0.001
y0<-ApproxSum(x=x,n=n,epsilon=eps);
> y0$s*(1+eps)
[1] 104.5955
> sum(x)
[1] 104.5719
> y0$s/(1+eps)
[1] 104.3866