[Rd] S3 - how to implement "colnames<-"
Have a class for which I would like to provide a "colnames<-.myclass" function so that colnames(myintsance) <- c("a","b","c") can be called. Witold -- Witold Eryk Wolski [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] legitimate use of :::
Am 14.05.2014 08:56, schrieb Deepayan Sarkar: On Wed, May 14, 2014 at 12:29 AM, Duncan Murdoch wrote: I think you are misunderstanding the comments in that file. It's an internal set of tests for the package, so "test some typical completion attempts" is a description of the tests that follow, it's not a suggestion that you should be able to run those lines from your package. If you do want access to the completion mechanism from a package, you should write to its author (Deepayan Sarkar) and explain the kinds of things you need to do. If you can convince him that giving you access is worth the trouble of exposing some of it to user-level code, then he'll export a function for you. (I think it's unlikely to be .win32consoleCompletion, but who knows.) Yes, .win32consoleCompletion() was meant for use by the Windows GUI, but I can see a use-case for something similar elsewhere (for example, ESS defines something analogous). But I don't immediately see why another R package should need this. If you have a legitimate use, we can discuss off-list and come up with a solution. As TinnR was used at the University I tried to update the TinnR package because it was removed from cran http://cran.rstudio.com/web/packages/TinnR/index.html I think they used the win32consoleCompletion to connect Tinnr (Windows) with R - I do not really know the reason. Actually I found that R-Studio is much better for R-beginner and available for all platforms. Thanks for your hints - but I will not solve this problem anymore Knut __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] large integer values
Dear devels, I need to create a (short) vector in C, which contains potentially very large numbers, exponentially to the powers of 2. This is my test example: lgth = 35; int power[lgth]; power[lgth - 1] = 1; for (j = 1; j < lgth; j++) { power[lgth - j - 1] = 2*power[lgth - j]; } Everything works ok until it reaches the limit of 2^32: power: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, -2147483648, 0, 0, 0 How should I declare the "power" vector, in order to accept integer values larger then 2^32? Thanks very much in advance, Adrian -- Adrian Dusa University of Bucharest Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] [R] S3 - how to implement "colnames<-"
Hi Witold, you should first of all redefine colnames to use UseMethod. Then you have to write a colnames.default that uses base::colnames (so that it does not interfere with existing code and other functions) and the you can define the method for your class. I would suggest, though, to use attributes for your object, rather than risking to mess up the default R function. Hope it helps, Cheers, Luca 2014-05-14 10:57 GMT+02:00 Witold E Wolski : > Have a class for which I would like to provide a "colnames<-.myclass" > function so that > > colnames(myintsance) <- c("a","b","c") > can be called. > > Witold > > > -- > Witold Eryk Wolski > > [[alternative HTML version deleted]] > > __ > r-h...@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. -- Luca Cerone Tel: +34 692 06 71 28 Skype: luca.cerone __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] large integer values
On 14/05/2014 10:37, Adrian Dușa wrote: Dear devels, I need to create a (short) vector in C, which contains potentially very large numbers, exponentially to the powers of 2. This isn't an R question, except in so far that R mandates the usual convention of C being 32-bit. However 1) You should use an unsigned integer type. 2) Most compilers have uint64_t but C99/C11 do not require it. They require uint_fast64_t and uintmax_t (which is the widest unsigned int) types. 3) double will hold much larger powers, and functions like pow_di (where supported) or pow will compute them efficiently for you. And R has R_pow_di in Rmath.h. This is my test example: lgth = 35; int power[lgth]; power[lgth - 1] = 1; for (j = 1; j < lgth; j++) { power[lgth - j - 1] = 2*power[lgth - j]; } Everything works ok until it reaches the limit of 2^32: power: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, -2147483648, 0, 0, 0 How should I declare the "power" vector, in order to accept integer values larger then 2^32? Thanks very much in advance, Adrian -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] large integer values
Dear Prof. Ripley, Once again, thank you for your replies. I must confess not being a genuine C programmer, having learned how to use C only in connection to R (and the macros provided are almost a separate language to learn). I'll try to read more about the types you've indicated, and will keep trying. So far, most certainly I am not doing it right, because all of them have the same result. Tried declaring: uint64_t power[lgth]; and uint_fast64_t power[lgth]; and uintmax_t power[lgth]; but still the top threshold appears at the limit of 32-bit in all cases. Will keep reading about these... Best wishes, Adrian On Wed, May 14, 2014 at 2:45 PM, Prof Brian Ripley wrote: > On 14/05/2014 10:37, Adrian DuÈa wrote: > >> Dear devels, >> >> I need to create a (short) vector in C, which contains potentially very >> large numbers, exponentially to the powers of 2. >> > > This isn't an R question, except in so far that R mandates the usual > convention of C being 32-bit. However > > 1) You should use an unsigned integer type. > 2) Most compilers have uint64_t but C99/C11 do not require it. They > require uint_fast64_t and uintmax_t (which is the widest unsigned int) > types. > 3) double will hold much larger powers, and functions like pow_di (where > supported) or pow will compute them efficiently for you. And R has > R_pow_di in Rmath.h. > > > >> This is my test example: >> >> lgth = 35; >> int power[lgth]; >> power[lgth - 1] = 1; >> for (j = 1; j < lgth; j++) { >> power[lgth - j - 1] = 2*power[lgth - j]; >> } >> >> Everything works ok until it reaches the limit of 2^32: >> >> power: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, >> 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, >> 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, >> 1073741824, -2147483648, 0, 0, 0 >> >> How should I declare the "power" vector, in order to accept integer values >> larger then 2^32? >> >> Thanks very much in advance, >> Adrian >> >> >> > > -- > Brian D. Ripley, rip...@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 > -- Adrian Dusa University of Bucharest Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] large integer values
On May 14, 2014, at 8:41 AM, Adrian Dușa wrote: > Dear Prof. Ripley, > > Once again, thank you for your replies. > I must confess not being a genuine C programmer, having learned how to use > C only in connection to R (and the macros provided are almost a separate > language to learn). > > I'll try to read more about the types you've indicated, and will keep > trying. So far, most certainly I am not doing it right, because all of them > have the same result. Tried declaring: > > uint64_t power[lgth]; > and > uint_fast64_t power[lgth]; > and > uintmax_t power[lgth]; > > but still the top threshold appears at the limit of 32-bit in all cases. > How do you print them? It seems like you're printing 32-bit value instead ... (powers of 2 are simply shifts of 1). Cheers, S > Will keep reading about these... > Best wishes, > Adrian > > > > On Wed, May 14, 2014 at 2:45 PM, Prof Brian Ripley > wrote: > >> On 14/05/2014 10:37, Adrian Dușa wrote: >> >>> Dear devels, >>> >>> I need to create a (short) vector in C, which contains potentially very >>> large numbers, exponentially to the powers of 2. >>> >> >> This isn't an R question, except in so far that R mandates the usual >> convention of C being 32-bit. However >> >> 1) You should use an unsigned integer type. >> 2) Most compilers have uint64_t but C99/C11 do not require it. They >> require uint_fast64_t and uintmax_t (which is the widest unsigned int) >> types. >> 3) double will hold much larger powers, and functions like pow_di (where >> supported) or pow will compute them efficiently for you. And R has >> R_pow_di in Rmath.h. >> >> >> >>> This is my test example: >>> >>> lgth = 35; >>> int power[lgth]; >>> power[lgth - 1] = 1; >>> for (j = 1; j < lgth; j++) { >>> power[lgth - j - 1] = 2*power[lgth - j]; >>> } >>> >>> Everything works ok until it reaches the limit of 2^32: >>> >>> power: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, >>> 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, >>> 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, >>> 1073741824, -2147483648, 0, 0, 0 >>> >>> How should I declare the "power" vector, in order to accept integer values >>> larger then 2^32? >>> >>> Thanks very much in advance, >>> Adrian >>> >>> >>> >> >> -- >> Brian D. Ripley, rip...@stats.ox.ac.uk >> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ >> University of Oxford, Tel: +44 1865 272861 (self) >> 1 South Parks Road, +44 1865 272866 (PA) >> Oxford OX1 3TG, UKFax: +44 1865 272595 >> > > > > -- > Adrian Dusa > University of Bucharest > Romanian Social Data Archive > 1, Schitu Magureanu Bd. > 050025 Bucharest sector 5 > Romania > Tel.:+40 21 3126618 \ >+40 21 3120210 / int.101 > Fax: +40 21 3158391 > > [[alternative HTML version deleted]] > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] large integer values
On Wed, May 14, 2014 at 5:35 PM, Simon Urbanek wrote: > [...] > > How do you print them? It seems like you're printing 32-bit value instead > ... (powers of 2 are simply shifts of 1). > > I am simply using Rprintf(): long long int power[lgth]; power[lgth - 1] = 1; Rprintf("power: %d", power[lgth - 1]); for (j = 1; j < lgth; j++) { power[lgth - j - 1] = 2*power[lgth - j]; Rprintf(", %d", power[lgth - j - 1]); } Basically, I need them in reversed order (hence the inverse indexing), but the values are nonetheless the same. Adrian PS: also tried long long int, same result... -- Adrian Dusa University of Bucharest Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] large integer values
On Wed, 2014-05-14 at 18:17 +0300, Adrian Dușa wrote: > On Wed, May 14, 2014 at 5:35 PM, Simon Urbanek > wrote: > > > [...] > > > > How do you print them? It seems like you're printing 32-bit value instead > > ... (powers of 2 are simply shifts of 1). > > > > > I am simply using Rprintf(): > > long long int power[lgth]; > power[lgth - 1] = 1; > Rprintf("power: %d", power[lgth - 1]); > for (j = 1; j < lgth; j++) { > power[lgth - j - 1] = 2*power[lgth - j]; > Rprintf(", %d", power[lgth - j - 1]); > } > > > Basically, I need them in reversed order (hence the inverse indexing), but > the values are nonetheless the same. > Adrian > > PS: also tried long long int, same result... Your numbers are being coerced to int when you print them. Try the format ", %lld" instead. Martyn __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S3 - how to implement "colnames<-"
Witold E Wolski gmail.com> writes: > > Have a class for which I would like to provide a "colnames<-.myclass" > function so that > > colnames(myintsance) <- c("a","b","c") > can be called. `colnames<-` is not generic as Luca noted. But `dimnames<-` is. If you write a suitable `dimnames<-.myinstance`, then `colnames<-` will find it. `dimnames<-.data.frame` gives an example. I think you will want to either call NextMethod() or replace attr(x,"dimnames") and return x. That is, you probably do not want to use `dimnames<-`inside `dimnames<-.myinstance`. HTH, Chuck __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Bug in read.dcf(all = TRUE)?
Hi, read.dcf() can modify the locale variable LC_CTYPE, and here is a minimal example: > Sys.getlocale('LC_CTYPE') [1] "en_US.UTF-8" > read.dcf(textConnection('a: b'), all = TRUE) a 1 b > Sys.getlocale('LC_CTYPE') [1] "C" After diagnosing the problem, it seems the on.exit() call in read.dcf() is the culprit: on.exit(Sys.setlocale("LC_CTYPE", Sys.getlocale("LC_CTYPE")), add = TRUE) Sys.setlocale("LC_CTYPE", "C") https://github.com/wch/r-source/blob/96a2cc920/src/library/base/R/dcf.R#L68-L69 > 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=en_US.UTF-8 [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.1.0 Regards, Yihui -- Yihui Xie Web: http://yihui.name __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] large integer values
On Wed, May 14, 2014 at 6:24 PM, Martyn Plummer wrote: > [...] > > Your numbers are being coerced to int when you print them. Try the > format ", %lld" instead. Oh my goodness, this was a printing issue...! (feeling embarrassed, but learned something new) Problem solved, thanks very much all, Adrian -- Adrian Dusa University of Bucharest Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel