[R] Problem with products in R ?

Gabor Grothendieck ggrothendieck at gmail.com
Tue May 6 05:42:42 CEST 2014


1. Firstly your library should be in user space.  Don't use the one in
C:\Program Files\... .  That is the case not only for bc but for other
packages too.  Reinstall R and the first time you install a package it
should ask you to allow it to create a user library.  Be sure you
allow that.

2. As indicated in the FAQ which bc you use  matters.  I am using the
one on the Downloads tab, i.e. here:

    https://code.google.com/p/r-bc/downloads/list

    If you are using a different bc then try this one.

3. Also ensure bc on your path.  From within R: Sys.which("bc") should
find it if its on your path.

4. I usually just source the bc.R file and that seems to work for me.
I just added a NAMESPACE file to the svn repo so that the package will
build and install on more recent versions of R.

This works for me on R 3.1 patched under Windows 8.1:

> source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
>  one <- bc(1)
> one
[1] "1"

and with the version of the repo that I just updated a few minutes ago
and building and installing bc in a separate session this works too:
> library(bc)
> bc(1)
[1] "1"


On Mon, May 5, 2014 at 11:09 PM, Richard M. Heiberger <rmh at temple.edu> wrote:
> Gabor,
>
> Can you confirm that the bc function is supposed to be current.
> The bc package works with my Mac, but not with Windows.
> I keep getting the message
>
> Error in system(cmd, input = input, intern = TRUE) : -l
>
> The FAQ on your https://code.google.com/p/r-bc/ page didn't get me past that
> problem.  I tried both the download bc.zip from the page and also the cygwin bc.
>
> A secondary issue is that placing your bc.exe into c:/Program
> Files/R/R-3.1.0/library/bc/bcdir/bc.exe
> gives the message
>> one <- bc(1)
> Error in system(cmd, input = input, intern = TRUE) :
>   'C:/Program' not found
>
> Working around that is possible with
>> bc.cmd <- "C:/Progra~1/R/R-3.1.0/library/bc/bcdir/bc.exe -l"
>> one <- bc(1, cmd=bc.cmd)
> but the next line gives the same problem
>> one
> Error in system(cmd, input = input, intern = TRUE) :
>   'C:/Program' not found
>
> Thanks
> Rich
>
>
> On Sun, May 4, 2014 at 1:10 PM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>> Checking this with the bc R package (https://code.google.com/p/r-bc/),
>> the Ryacas package (CRAN), the gmp package (CRAN) and the Windows 8.1
>> calculator all four give the same result:
>>
>>> library(bc)
>>> bc("168988580159 * 36662978")
>> [1] "6195624596620653502"
>>
>>> library(Ryacas)
>>> yacas("168988580159 * 36662978", retclass = "character")
>> 6195624596620653502
>>
>>> library(gmp)
>>> as.bigz("168988580159") * as.bigz("36662978")
>> Big Integer ('bigz') :
>> [1] 6195624596620653502
>>
>>
>> On Sun, May 4, 2014 at 12:50 PM, Ted Harding <Ted.Harding at wlandres.net> wrote:
>>> On 04-May-2014 14:13:27 Jorge I Velez wrote:
>>>> Try
>>>>
>>>> options(digits = 22)
>>>> 168988580159 * 36662978
>>>># [1] 6195624596620653568
>>>>
>>>> HTH,
>>>> Jorge.-
>>>
>>> Err, not quite ... !
>>> I hitch my horses to my plough (with help from R):
>>>
>>> options(digits=22)
>>> 168988580159*8 = 1351908641272 (copy down)
>>> 168988580159*7 = 1182920061113  ( " " )
>>> 168988580159*9 = 1520897221431  ( " " )
>>> 168988580159*2 =  337977160318  ( " " )
>>> 168988580159*6 = 1013931480954  ( " " )^3
>>> 168988580159*3 =  506965740477  ( " " )
>>>
>>>          1351908641272
>>>         11829200611130
>>>        152089722143100
>>>        337977160318000
>>>      10139314809540000
>>>     101393148095400000
>>>    1013931480954000000
>>>    5069657404770000000
>>> ======================
>>>    6195624596620653502
>>> [after adding up mentally]
>>>
>>> compared with Jorge's:
>>>    6195624596620653568
>>>
>>> ("02" vs "68" in the final two digits).
>>>
>>> Alternatively, if using a unixoid system with 'bc' present,
>>> one can try interfacing R with 'bc'. 'bc' is an calculating
>>> engine which works to arbitrary precision.
>>>
>>> There certainly used to be a utility in which R can evoke 'bc',
>>> into which one can enter a 'bc' command and get the result
>>> returned as a string, but I can't seem to find it on CRAN now.
>>> In any case, the raw UNIX command line for this calculation
>>> with 'bc' (with result) is:
>>>
>>> $ bc -l
>>> [...]
>>> 168988580159 * 36662978
>>> 6195624596620653502
>>> quit
>>>
>>> which agrees with my horse-drawn working.
>>>
>>> Best wishes to all,
>>> Ted.
>>>
>>>> On Sun, May 4, 2014 at 10:44 PM, ARTENTOR Diego Tentor <
>>>> diegotentor71 at gmail.com> wrote:
>>>>
>>>>> Trying algorithm for products with large numbers i encountered a difference
>>>>> between result of 168988580159 * 36662978 in my algorithm and r product.
>>>>> The Microsoft calculator confirm my number.
>>>>>
>>>>> Thanks.
>>>>> --
>>>>> *        Gráfica ARTENTOR          *
>>>>>
>>>>> de Diego L. Tentor
>>>>> Echagüe 558
>>>>> Tel.:0343 4310119
>>>>> Paraná - Entre Ríos
>>>
>>> -------------------------------------------------
>>> E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
>>> Date: 04-May-2014  Time: 17:50:54
>>> This message was sent by XFMail
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>> --
>> Statistics & Software Consulting
>> GKX Group, GKX Associates Inc.
>> tel: 1-877-GKX-GROUP
>> email: ggrothendieck at gmail.com
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list