Re: [R] [External] Amazing AI

2022-12-21 Thread Barry Rowlingson
Next year one of my R programming assigments will read like this:

"Here is some R code written by a multi-million dollar AI system to
compute [something]. It doesn't work. Fix the bugs, then ask the AI to
write a letter to its creators apologising for how rubbish it is at
coding. Collect one million dollars."


On Sun, Dec 18, 2022 at 7:01 PM Boris Steipe  wrote:
>
> This email originated outside the University. Check before clicking links or 
> attachments.
>
> Technically not a help question. But crucial to be aware of, especially for 
> those of us in academia, or otherwise teaching R. I am not aware of a 
> suitable alternate forum. If this does not interest you, please simply ignore 
> - I already know that this may be somewhat OT.
>
> Thanks.
> --
>
> You very likely have heard of ChatGPT, the conversation interface on top of 
> the GPT-3 large language model and that it can generate code. I thought it 
> doesn't do R - I was wrong. Here is a little experiment:
>
> MY PROMPT:
> ==
> Please write me some R code that will read a tsv file, remove all rows that 
> have duplicates in the column "names", and store the median values of the 
> remaining rows in a variable called "Medians". Of course, that calculation 
> should only be done with columns that are numeric. Print the last variable in 
> order from largest to smallest.
>
>
> AI RESPONSE:
> 
>
> Here is some R code that should accomplish what you've described:
>
> (Note: the code is formatted in a little terminal window, complete with a 
> button to "copy code" at the top.)
>
> 
> # Read the tsv file
> data <- read.table("file.tsv", header = TRUE, sep = "\t")
>
> # Remove rows with duplicates in the "names" column
> data <- data[!duplicated(data$names), ]
>
> # Select only the numeric columns
> num_columns <- sapply(data, is.numeric)
> numeric_data <- data[, num_columns]
>
> # Calculate the medians for each column
> Medians <- apply(numeric_data, 1, median)
>
> # Sort Medians in descending order
> Medians <- sort(Medians, decreasing = TRUE)
>
> # Print Medians
> print(Medians)
> 
>
> This code assumes that the tsv file is called "file.tsv" and is stored in the 
> current working directory. It also assumes that the first row of the file 
> contains the column names.
>
>
>
> MY PROMPT:
> ==
> Can you provide me with a bit of sample data that I can use to test this code?
>
> AI RESPONSE:
> 
> Certainly! Here is some sample data that you can use to test the code I 
> provided:
>
> 
> nameage height  weight
> Alice   23  5.6 120
> Bob 32  6.2 180
> Charlie 29  5.9 160
> Alice   23  5.6 120
> David   25  5.8 140
> Eve 27  5.5 110
> 
>
> You can save this data as a tsv file and use it to test the code.
>
>
> --
>
> Notes:
> 1) The code, as written does not work with the test data. The reason is that 
> the test data specifies a column "name", but the code assumes "names" (which 
> I specified in the instructions). Once this is fixed in the test data, the 
> code executes.
>
> 2) The instructions are not accurately translated: I had asked for row means. 
> But changing the margin in the apply() statement from 2 to 1 does the correct 
> thing.
>
> 3) Note that the test data contains both numeric and non-numeric columns. 
> Also, the name "Alice" is duplicated in the test data, which is subtle, and 
> the right thing to do.
>
>
> --
>
> A similar experiment, run on the beta-site of OpenAI's Codex code-completion 
> tool gives the following code (complete with the comments.):
>
> 
> # Read in the data
> data <- read.table("mydata.tsv", sep = "\t", header = TRUE)
>
> # Remove all rows that have duplicates in the column "names"
> unique_names <- unique(data$names)
> data_unique <- data[data$names %in% unique_names,]
>
> # Calculate medians
> Medians <- sapply(data_unique[, sapply(data_unique, is.numeric)], median, 
> na.rm = TRUE)
>
> # Print last variable in order form largest to smallest
> rev(sort(Medians[length(Medians)]))
> 
>
> Note that the strategy is quite different (e.g using %in%, not duplicated() 
> ), the interpretation of "last variable" is technically correct but not what 
> I had in mind (ChatGPT got that right though).
>
>
> Changing my prompts slightly resulted it going for a dplyr solution instead, 
> complete with %>% idioms etc ... again, syntactically correct but not giving 
> me the fully correct results.
>
> --
>
> Bottom line: The AI's ability to translate natural language instructions into 
> code is astounding. Errors the AI makes are subtle and probably not easy to 
> fix if you don't already know what you are doing. But the way that this can 
> be "confidently incorrect" and plausible makes it nearly 

Re: [R] [External] Re: Is there a canonical way to pronounce CRAN?

2022-05-05 Thread Barry Rowlingson
If the founders had called it the Big R Archive Network we wouldn't be
having this discussion but we'd all be getting our packages from BRAN.

Or how about "Big R Internet Archive Network" Or would that be
confusing...

Barry

On Wed, May 4, 2022 at 3:51 PM Kevin Thorpe 
wrote:

> This email originated outside the University. Check before clicking links
> or attachments.
>
> Interesting.
>
> I have always pronounced it as See-ran. This probably stems from my
> exposure to other archive like CPAN (perl) and CTAN (TeX) that I have been
> exposed to. Obviously the latter two acronyms are unpronounceable as words
> so I generalized the approach to CRAN.
>
> Kevin
>
>
> > On May 4, 2022, at 7:20 AM, Roland Rau via R-help 
> wrote:
> >
> > Dear all,
> >
> > I talked with colleagues this morning and we realized that some people
> (=me) pronounce CRAN like the German word "Kran" (probably pronounced like
> "cruhn" in English -- if it was a word).
> > My colleague pronounced it as "Sea-Ran" or "Sea-Run". The colleague was
> a student and has worked at the same institution as an R Core Developer and
> heard it from him personally.
> >
> > So now I am puzzled. Have I been wrong about 43% of my life? ;-)
> >
> > Honestly: Is there a unique way how the core developers prounounce CRAN?
> >
> > Not an urgent question at all but maybe interesting to many of us.
> >
> > Thanks,
> > Roland
> >
> > --
> > This mail has been sent through the MPI for Demographic ...{{dropped:2}}
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
> --
> Kevin E. Thorpe
> Head of Biostatistics,  Applied Health Research Centre (AHRC)
> Li Ka Shing Knowledge Institute of St. Michael’s Hospital
> Assistant Professor, Dalla Lana School of Public Health
> University of Toronto
> email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Greek characters in R studio

2019-04-10 Thread Barry Rowlingson
What have you tried? read.table works perfectly for me with no language or
encoding arguments. Here's a text file at the Linux command line:

$ cat greek.csv
α, β
1,2
3,4

I just have to tell it to use comma separators and there is a header line.
Here's R:

> read.table("./greek.csv",sep=",",head=TRUE)
  α β
1 1 2
2 3 4

and I can get the columns in the usual way:

> d[["α"]]
[1] 1 3
> d$α
[1] 1 3

But maybe this doesn't work for you. Did you try anything? What happened?

B

On Tue, Apr 9, 2019 at 3:13 AM kostas zogopoulos 
wrote:

> How do you read a csv file that contains greek characters as part of the
> header (i.e. α, β etc) in R studio?
>  Thanks in advance!
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] getting 21 very different colours

2018-09-11 Thread Barry Rowlingson
On Tue, Sep 11, 2018 at 11:43 AM, Duncan Murdoch 
wrote:

> On 11/09/2018 3:34 AM, Federico Calboli wrote:
> > Hi All,
> >
> > I am plotting a scatterplot of 21 populations, and I am using
> rainbow(21)[pops.col] to generate 21 colours for the plot (which works).
> Maybe it is because I can really process few colours at a time, but the
> differences between the colours are not as strong as I’d like.  I can
> specify start and end for rainbow(), but if anything that looks worse if I
> do not just stick to 0 and 1.
> >
> > Is there a way of getting a set of 21 colours that maximises the
> differences between them?
>
> The LAB and LUV color spaces (in the colorspace package) attempt to map
> perceptual differences to equal distances.  You could try using a grid
> of points in one of those spaces, but not all triples are valid.
>
> However, 21 colours is probably too many for your purpose.  If you
> really want to distinguish 21 groups, you're likely going to have to use
> other characteristics as well, such as the symbol.  You could plot 21
> different letters in 5 different colours and it might work, but it's not
> going to be easy for viewers.
>
>
The `alphabet` and `alphabet2` palettes from the `pals` package claim 26
"distinguishable" colours:

Details:

 The ‘alphabet’ palette has 26 distinguishable colors that have
 logical names starting with the English alphabet letters A, B, ...
 Z. This palette is based on the work by Green-Armytage (2010), but
 uses the names 'orange' instead of 'orpiment', and 'magenta'
 instead of 'mallow'.

There are some other palettes in that help page (?alphabet) that might also
work. But 21 colours is pushing it.

Barry






> Duncan Murdoch
>
> >
> > I could pick them by hand, but that is about 15 colours more than I know
> (I have a detailed colourchart, but the visual differences between
> ’skyblue’ and ’slategrey’ elude me when plotted as dots on a plot).
> >
> > Cheers
> >
> > F
> > --
> > Federico Calboli
> > LBEG - Laboratory of Biodiversity and Evolutionary Genomics
> > Charles Deberiotstraat 32 box 2439
> > 3000 Leuven
> > +32 16 32 87 67
> >
> >
> >
> >
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
> >
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] security using R at work

2018-08-09 Thread Barry Rowlingson
On Thu, Aug 9, 2018 at 9:14 AM, Jan van der Laan  wrote:
> You can also inadvertently transmit data to the internet using a package
> without being obviously 'stupid', e.g. by using a package that uses an
> external service for data processing. For example, some javascript
> visualisation libs can do that (not sure if those wrapped in R-packages
> do), or, for example, a geocoding service.

 Ooh yes, that's probably a whole new category.  Maybe "Unwittingly"
describes this - it could be the users fault for not reading or
understanding the documentation or the package authors fault for not
documenting the network activity properly. Leave that one to the
lawyers to decide.

Barry

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] security using R at work

2018-08-08 Thread Barry Rowlingson
On Wed, Aug 8, 2018 at 4:09 PM, Laurence Clark
 wrote:
> Hello all,
>
> I want to download R and use it for work purposes. I hope to use it to 
> analyse very sensitive data from our clients.
>
> My question is:
>
> If I install R on my work network computer, will the data ever leave our 
> network? I need to know if the data goes anywhere other than our network, 
> because this could compromise it's security.

> Is there is any chance the data could go to a server owned by 'R' or anything 
> else that's not immediately obvious, but constitutes the data leaving our 
> network?

You are talking mostly to statisticians here, and if p>0 then there's
"a chance". I'd say yes, there's a chance, but its pretty small, and
would only occur through stupidity, accident or malice.

 In the ordinary course of things your data will be on your hard disk,
or on your corporate network drives, and only exist between your
corporate network server and your PC's memory. R will load the data
into that memory, do stuff with it in that memory, and write results
back to hard disk. Nothing leaves the network this way.

However... R has facilities for talking to the internet. You can save
data to google docs spreadsheets, for example, but you'd have to be
signed in to google, and have to type something like:

 > writeGoogleDoc(my_data, "secretdata.xls")

that covers "stupid". You should know that google docs are on google's
servers, and google's servers aren't on your network, and your secret
data shouldn't go on google's servers.

Accidents happen. You might be working on non-secret data which you
want to save to google docs, and accidentally save "data1" which is
secret instead of "data2" which is okay to be public. Oops. You sent
it to google. Accidents happen.

"malice" would be if someone had put code into R or an add-on package
that you use that sends your data over the network without you
knowing. For example maybe every time you fit a linear model with:

 lm(age~beauty, data=people)

R could be transmitting the data to hackers. But the chance of this is
very small, and I don't think any malicious code has ever been
discovered in R or the 12000 add-on packages downloadable from CRAN.
Doesn't mean it hasn't been discovered yet or won't be in the future.

It used to be said that the only machine safe from hackers was one
unplugged from the network. But now hackers can get to your machine
via malicious USB sticks, keyboard loggers, and various other nasties.
The only machine safe from hackers is one with the power off. But take
the power plug out because a wake-on-lan packet could switch your
machine on remotely

Barry







> Thank you
>
> Laurence
>
>
> --
> Laurence Clark
> Business Data Analyst
> Account Management
> Health Management Ltd
>
> Mobile: 07584 556498
> Switchboard:0845 504 1000
> Email:  laurence.cl...@healthmanltd.com
> Web:www.healthmanagement.co.uk
>
> --
> CONFIDENTIALITY NOTICE: This email, including attachments, is for the sole 
> use of the intended recipients and may contain confidential and privileged 
> information or otherwise be protected by law. Any unauthorised review, use, 
> disclosure or distribution is prohibited. If you are not the intended 
> recipient, please contact the sender, and destroy all copies and the original 
> message.MAXIMUS People Services Limited is registered in England and 
> Wales (registered number: 03752300); registered office: 202 - 206 Union 
> Street, London, SE1 0LX, United Kingdom. The Centre for Health and Disability 
> Assessments Ltd (registered number: 9072343) and Health Management Ltd 
> (registered number: 4369949) are registered in England and Wales. The 
> registered office for each is Ash House, The Broyle, Ringmer, East Sussex, 
> BN8 5NN, United Kingdom. Remploy Limited is registered in England and Wales 
> (registered number: 09457025); registered office: 18c Meridian East, Meridian 
> Business Park, Leicester,
  Leicestershire, LE19 1WZ, United Kingdom.
> --
>
>
> --
>
>
> #
> Scanned by MailMarshal - M86 Security's comprehensive email content security 
> solution.
> Download a free evaluation of MailMarshal at www.m86security.com
> 

Re: [R] prod(NaN, NA) vs. prod(NA, NaN)

2018-07-04 Thread Barry Rowlingson
I'm having deja-vu of a similar discussion on R-devel:

https://stat.ethz.ch/pipermail/r-devel/2018-July/076377.html

This was the funniest inconsistency I could find:

 > sum(c(NaN,NA))
 [1] NaN
 > sum(NaN,NA)
 [1] NA

THEY'RE IN THE SAME ORDER!!!

The doc in ?NaN has this clause:

 In R, basically all mathematical functions (including basic
 ‘Arithmetic’), are supposed to work properly with ‘+/- Inf’ and
 ‘NaN’ as input or output.

which doesn't define "properly", but you'd think commutativity was a
"proper" property of addition. So although they "are supposed to" they
don't. Naughty mathematical functions!

And then there's...

 Computations involving ‘NaN’ will return ‘NaN’ or perhaps ‘NA’:
 which of those two is not guaranteed and may depend on the R
 platform (since compilers may re-order computations).

Which is at least telling you there is vagueness in the system. But
hey, mathematics is not a precise science... oh wait...

Barry





On Tue, Jul 3, 2018 at 10:09 PM, Rolf Turner  wrote:
>
> On 04/07/18 00:24, Martin Møller Skarbiniks Pedersen wrote:
>
>> Hi,
>>I am currently using R v3.4.4 and I just discovered this:
>>
>>> prod(NA, NaN) ; prod(NaN, NA)
>> [1] NA
>> [1] NaN
>>
>> ?prod says:
>>  If ‘na.rm’ is ‘FALSE’ an ‘NA’ value in any of the arguments will
>>   cause a value of ‘NA’ to be returned, otherwise ‘NA’ values are
>>   ignored.
>>
>> So according to the manual-page for prod() NA should be returned in both
>> cases?
>>
>>
>> However for sum() is opposite is true:
>>> sum(NA, NaN) ; sum(NaN, NA)
>> [1] NA
>> [1] NA
>>
>> ?sum says:
>>  If ‘na.rm’ is ‘FALSE’ an ‘NA’ or ‘NaN’ value in any of the
>>   arguments will cause a value of ‘NA’ or ‘NaN’ to be returned,
>>   otherwise ‘NA’ and ‘NaN’ values are ignored.
>>
>>
>> Maybe the manual for prod() should say the same as sum() that
>> both NA and NaN can be returned?
>
> But:
>
>  > sum(NA,NaN)
> [1] NA
>  > sum(NaN,NA)
> [1] NA
>
> so sum gives NA "both ways around".  Perhaps a slight inconsistency
> here?  I doubt that it's worth losing any sleep over, however.
>
> Interestingly (???):
>
>  > NaN*NA
> [1] NaN
>  > NA*NaN
> [1] NA
>  > NaN+NA
> [1] NaN
>  > NA+NaN
> [1] NA
>
> So we have an instance of non-commutative arithmetic operations.  And
> sum() is a wee bit inconsistent with "+".
>
> Again I doubt that the implications are all that serious.
>
> cheers,
>
> Rolf Turner
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Learning advanced R

2018-03-14 Thread Barry Rowlingson
Depending on your application, I'm not sure there's much point in being an
"advanced R programmer" these days. Become an adequate R programmer, and
learn C++ and Rcpp. Do basic data mashing in R, then do all your intensive
stuff in C++ with Rcpp. Eventually you'll probably get to the point where
you can express yourself in C++ as fast as you can in interpreted R, with
the bonus of C++ speed, type-safety etc.



On Wed, Mar 14, 2018 at 8:13 AM, Eric Berger  wrote:

> Bert's suggestion is good as a pointer to a variety of resources.
> Sticking to the book format there are two of Hadley Wickham's books, which
> have the advantage that they are freely available.
> You can either read them online or download the source from github and
> create your own copy (which you can then print, if desired.)
> 1. "R for Data Science"
>  online: http://r4ds.had.co.nz/
>  github: https://github.com/hadley/r4ds
> 2. "Advanced R"
>  online: https://adv-r.hadley.nz/
>  github: https://github.com/hadley/adv-r
>
> Best,
> Eric
>
>
>
> On Wed, Mar 14, 2018 at 12:13 AM, Rich Shepard 
> wrote:
>
> > On Tue, 13 Mar 2018, Mark Leeds wrote:
> >
> > See Hadley's advanced R
> >>
> >
> >   +1 A very well writte, highly useful book. Recommended.
> >
> > Rich
> >
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posti
> > ng-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] reading lisp file in R

2018-01-18 Thread Barry Rowlingson
The file also has a bunch of email headers stuck in the middle of it:


.

 (QUALITY-OF-LIFE SCALE:1-5 4)
  (ACADEMIC-EMPHASIS HEALTH-SCIENCE)
)
---
---

>From lebow...@cs.columbia.edu Mon Feb 22 20:53:02 1988
Received: from zodiac by meridian (5.52/4.7)
Received: from Jessica.Stanford.EDU by ads.com (5.58/1.9)
id AA04539; Mon, 22 Feb 88 20:59:59 PST
Received: from Portia.Stanford.EDU by jessica.Stanford.EDU with TCP; Mon,
22 Feb
 88 20:58:22 PST
Received: from columbia.edu (COLUMBIA.EDU.ARPA) by Portia.STANFORD.EDU
(1.2/Ultrix2.0-B)
id AA11480; Mon, 22 Feb 88 20:49:53 pst
Received: from CS.COLUMBIA.EDU by columbia.edu (5.54/1.14)
id AA10186; Mon, 22 Feb 88 23:48:44 EST
Message-Id: <8802230448.aa10...@columbia.edu>
Date: Fri 22 Jan 88 02:50:00-EST
From: The Mailer Daemon 
To: lebow...@cs.columbia.edu
Subject: Message of 18-Jan-88 20:13:54
Resent-Date: Mon 22 Feb 88 23:44:07-EST
Resent-From: Michael Lebowitz 
Resent-To: soud...@portia.stanford.edu
Resent-Message-Id: <12376918538.25.lebow...@cs.columbia.edu>
Status: R

Message undeliverable and dequeued after 3 days:
souders%merid...@ads.arpa: Cannot connect to host

Date: Mon 18 Jan 88 20:13:54-EST
From: Michael Lebowitz 
Subject: bigger file part 3
To: souders%merid...@ads.arpa
In-Reply-To: <8801182147.aa08...@ads.arpa>
Message-ID: <12367705229.11.lebow...@cs.columbia.edu>

(DEF-INSTANCE GEORGETOWN
  (STATE MARYLAND)
  (LOCATION URBAN)
  (CONTROL PRIVATE)
  (NO-OF-STUDENTS THOUS:10-15)
  (MALE:FEMALE RATIO:45:55)


Which dates it to 1988. Nice.

Barry



On Thu, Jan 18, 2018 at 9:20 AM, Peter Crowther  wrote:

> That's a nice example of why Lisp is both powerful and terrifying - you're
> looking at a Lisp *program*, not just Lisp *data*, as Lisp makes no
> distinction between the two.  You just read 'em in.
>
> The two definitions at the bottom are function definitions.  The top one
> defines the def-instance function.  Reading that indicates that it accepts
> an atom as a name and a list of key-value or key-range-value lists as
> properties, where they keys may be repeated to give you multi-valued
> attributes in your result.  The bottom one defines a function for removing
> duplicate entries of the same location.
>
> The rest of the file (apart from the included email headers) is a whole
> load of calls to the def-instance function.  In Lisp, you'd define the
> functions, then just run the rest of the file.
>
> To my knowledge, there is no generic way to read Lisp "data" into anything
> else, because of this quirk that data can look like anything.  If anyone
> can correct me on that, great, but I'd be somewhat surprised.  Therefore,
> as David intimated, the tools you need are generic tools for handling text,
> and you'll have to deal with the formatting yourself.  If I were doing a
> one-off transform of this file, I'd probably reach for vi... but I'm an old
> Unix hacker.  I certainly wouldn't teach that tooling.  awk or perl could
> certainly handle it; or if you want to give students a wider view of the
> world you might wish to try ANTLR and get them to write a grammar to parse
> the file.  The Clojure grammar (
> https://github.com/antlr/grammars-v4/blob/master/clojure/Clojure.g4) would
> be an interesting place to start, although Terence Parr's comment of "match
> a bunch of crap in parentheses" would probably give a flavour of what to
> implement.  Depends what else the students are learning.
>
> Hope this helps rather than hinders.
>
> - Peter
>
> On 18 January 2018 at 05:25, Ranjan Maitra  wrote:
>
> > Thanks! I am trying to use it in R. (Actually, I try to give my students
> > experiences with different kinds of files and I was wondering if there
> were
> > tools available for such kinds of files. I don't know Lisp so I do not
> > actually know what the lines towards the bottom of the file mean.(
> >
> > Many thanks for your response!
> >
> > Best wishes,
> > Ranjan
> >
> > On Wed, 17 Jan 2018 20:59:48 -0800 David Winsemius <
> dwinsem...@comcast.net>
> > wrote:
> >
> > >
> > > > On Jan 17, 2018, at 8:22 PM, Ranjan Maitra  wrote:
> > > >
> > > > Dear friends,
> > > >
> > > > Is there a way to read data files written in lisp into R?
> > > >
> > > > Here is the file: https://archive.ics.uci.edu/
> > ml/machine-learning-databases/university/university.data
> > > >
> > > > I would like to read it into R. Any suggestions?
> > >
> > > It's just a text file. What difficulties are you having?
> > > >
> > > >
> > > > Thanks very much in advance for pointers on this and best wishes,
> > > > Ranjan
> > > >
> > > > --
> > > > Important Notice: This mailbox is ignored: e-mails are set to be
> > deleted on receipt. Please respond to the mailing list if appropriate.
> For
> > those needing to send personal or professional e-mail, please use
> > appropriate addresses.
> > 

Re: [R] Vibration signal prediction in R

2017-08-24 Thread Barry Rowlingson
On Thu, Aug 24, 2017 at 7:07 AM, David Winsemius 
wrote:

>
> > On Aug 23, 2017, at 10:06 PM, Dhivya Narayanasamy 
> wrote:
> >
> > I have a vibration signal coming accelerometer. I converted this signal
> from*
> > m/s^2* to *mm/s*. Now I am supposed to predict this vibration signal in R
> > using historical data. (Please see the attached picture of vibration
> > signal).
>
> The dimensional analysis of the second sentence does not make scientific
> sense.
>
>
Not so! If you know the initial v and a(t) you can compute v(t) by
integration.

For example if you drop something then v(0)=0, a(t)=-g, then you can
compute v(t)

The question has been posted to Data Science Stack Exchange if anyone wants
to see the picture...

https://datascience.stackexchange.com/questions/22466/processing-the-vibration-signal-before-prediction

Barry

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Beginner’s Question

2017-06-12 Thread Barry Rowlingson
On Mon, Jun 12, 2017 at 2:39 AM, Neil Salkind  wrote:
> Please excuse the naive question but my first hour with RStudio, resulted in 
> this…
>
>> data()
>> data(“women”)
> Error: unexpected input in "data(�”
>
> So,that did not work but
>
>>data(women)
>
> without the quotes did.
>
> Would someone be so kind as to explain the function of quotes in RStudio? 
> Thanks, Neil

First of all this is R, not RStudio. R is the language, the core, it
does all the computation. RStudio is just a pretty wrapper that lets
you click menus and arranges all your windows for you because it
thinks it knows how to arrange windows better than your operating
system. But I digress.

Quotes in R are used to define character strings. You can use single
or double quotes, but the exact same quote mark is used at the start
and finish. Unlike in proper books, R doesn't use "66" quotes at the
start and "99" quotes at the end of a string. Some word processors
will magically change standard plain quotes to super cute 66 and 99
quotes which seems to be how they may have sneaked into your RStudio
session.

Now in R, if you just type a word it usually means the value of the
thing with that name. So there's a difference between:

 x = y

and

 x = "y"

In the first case, x is going to get the value of an object called y,
and if there is no object called y it will error. In the second case x
is going to get the character value "y", and there's no object called
y involved at all. But there are exceptions

The library function is probably the first exception people come
across. You can type:

library(stats)

without using any quotes, and even though there's no object called
stats, you don't get an error. The code in the library function uses
special powers to look at what you typed rather than the value of an
object called stats that you passed to the function. This means that
although there is a package called ggplot2 on my system, this doesn't
work:

 > thing="ggplot2"
 > library(thing)
 Error in library(thing) : there is no package called ‘thing’

It looks for a package called thing rather than one called ggplot2. Surprise!

You *can* pass a character string value to library, so both
library(ggplot2) and  library("ggplot2") both work the same.

The data function is another function that uses the same methods as
library to get what you asked for. So (once you get your quotes
straightened out) you can do:

data(women)

or (double quotes):

data("women")

or (single quotes):

data('women')

Those of us who see this kind of behaviour as an impurity in a
language shudder when we think about it - names are names and strings
are strings - but others are grateful for saving two keystrokes every
time they type library(ggplot2).


> *
> Whenever the people are well informed, they can be trusted with their own 
> government.  ~ ~ ~Thomas Jefferson
>
> Neil J. Salkind
> (785) 841-0947
> neiljsalk...@gmail.com
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Whitespace

2017-05-01 Thread Barry Rowlingson
That looks like an error from Stan parsing your stan file, but the
code you put in the message doesn't look like Stan code, it looks like
R code, so maybe you've tried to parse your R code with Stan

There's no mention of stan in the code either, like the rstan package,
so somehow you've got a Stan error message from some R code without
calling stan... Okay, I'm well confused now...





On Mon, May 1, 2017 at 5:57 AM, Miguel Angel Hombrados Herrera
 wrote:
> Hello
>
>
> Ive been working on a stan program in Rstudio. Im kind of new on this, so 
> probably my question is trivial, However I was not able to find information 
> about this.
>
> The error Im getting when I run my stan code is:
>
>
> PARSER EXPECTED: whitespace to end of file.
> FOUND AT line 2:
>
>
> The code is:
>
> iter=500
> alphamcmc=matrix(0,ncol=J,nrow=iter)
> betamcmc=NULL
> mu_alpha=NULL
> sigma_alpha_2=NULL
> sigma_y_2=NULL
> #set initial values
> alphamcmc[1,]=rep(mean(y),J)
> betamcmc[1]=70
> mu_alpha[1]=mean(y)
> sigma_alpha_2[1]=300
> sigma_y_2[1]=350
> #mcmc iteration
> for(m in 2:iter){
> #update alpha vector
> for(j in 1:J){
> sj=sum(source==j)
> var=1/(sj/sigma_y_2[m-1]+1/sigma_alpha_2[m-1])
> temp=0
> for(i in 1:N){temp=temp+1*(source[i]==j)*(y[i]-betamcmc[m-1]*x[i])}
> #sum up (y_i-beta x_i ) for those belonging to group j
> mean=var*(temp/sigma_y_2[m-1]+mu_alpha[m-1]/sigma_alpha_2[m-1])
> alphamcmc[m,j]=rnorm(1,mean,sqrt(var))
> }
> #update beta
> var=sigma_alpha_2[m-1]/(sum(x^2))
> mean=sum(x%*%(y-alphamcmc[m,source])/sum(sum(x^2)))
> betamcmc[m]=rnorm(1,mean,sqrt(var))
> #update mu_alpha
> #update sigma_alpha_2
> sigma_alpha_2[m]=rinvgamma(1,shape=J/2,rate=sum((alphamcmc[m,]
> -mu_alpha[m])^2/2))
> #update sigma_y_2
> sigma_y_2[m]=rinvgamma(1,shape=N/2,rate=sum((y-alphamcmc[m,source]-
> betamcmc[m]*x)^2/2))
> }
> nburn=200
> apply(alphamcmc[(nburn+1):iter,],2,mean)
> apply(betamcmc[(nburn+1):iter],2,mean)
>
> Ive been searching for wrong spaces or tabulations, but I was not able to 
> find anything.
>
> I really would appreciate your help.
> Thaknk you.
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] help on readBin in R

2017-04-17 Thread Barry Rowlingson
There's very little justification for attaching binary files to a
mailing list these days - share it on Dropbox, or Box, or Hubic, or
whatever MS or Google's cloud storage is, or simply tell us where it
was obtained from originally.

And to the original poster - some more context is very useful - where
did you get it from, what area is it supposed to cover, etc etc.

I hope you don't want to do any serious science with a data file that
you have no provenance for.



On Mon, Apr 17, 2017 at 4:13 AM, Jeff Newmiller
 wrote:
> That may or may not work, since text file newlines get altered in them. May 
> have more luck with a "png" extension?
> --
> Sent from my phone. Please excuse my brevity.
>
> On April 16, 2017 7:33:06 PM PDT, jim holtman  wrote:
>>If the file is not too large, just change the extension to '.txt' and
>>attach it.  Also include the code that you are using to read it in and
>>a definition of the what the data is; e.g., first two byte are
>>temperature, next four bytes are a station ID, 
>>
>>Here is an example of reading in a binary file and I know that the
>>'raw' output matches the bytes that are in the file:
>>
>>> infile <- file("test.txt", 'rb')
>>>
>>> input <- readBin(infile, raw(), 100)
>>>
>>> input
>>  [1] 50 4b 03 04 14 00 04 00 08 00 47 95 90 4a 9f 00 7a a0 99 01 00
>>00 7a 08 00 00 13 00 75 00 5b 43 6f
>> [34] 6e 74 65 6e 74 5f 54 79 70 65 73 5d 2e 78 6d 6c 53 44 60 00 a4
>>00 00 00 00 08 00 32 fa a9 3f 63 64
>> [67] 60 69 11 61 60 60 30 00 62 10 f0 01 62 46 56 30 93 55 14 48 55
>>e8 cd 15 fe e5 cf a3 df 6c ab ed 66
>>[100] b1
>>>
>>
>>here is the dump:
>>
>>$ od -a -t x --endian=big test.txt
>>000   P   K etx eot dc4 nul eot nul  bs nul   G nak dle   J  us nul
>>   504b03041400040008004795904a9f00
>>020   z  sp  em soh nul nul   z  bs nul nul dc3 nul   u nul   [   C
>>   7aa099017a08130075005b43
>>040   o   n   t   e   n   t   _   T   y   p   e   s   ]   .   x   m
>>   6f6e74656e745f54797065735d2e786d
>>
>>Jim Holtman
>>Data Munger Guru
>>
>>What is the problem that you are trying to solve?
>>Tell me what you want to do, not how you want to do it.
>>
>>
>>On Sun, Apr 16, 2017 at 9:21 PM, Jeff Newmiller
>> wrote:
>>> The mailing list has tight restrictions on attachments, so your
>>attachment was not let through. Read the Posting Guide, and note that
>>sometimes success requires some extended understanding of how your mail
>>software works, and we probably don't know the details either. You
>>might have success changing the file extension or sending a link to the
>>file on a file storage website like Google Drive or Dropbox.
>>> --
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> On April 16, 2017 3:49:07 PM PDT, "M.M saifuddin"
>> wrote:
I need to view the attached  binary file. but can not read it,
>>instead
am
getting very weird( i think garbage) numbers.

The values are Temperature data so it should be somewhat in between
>>250
to
500.

Can any altruist view it and give me the R code to view it.

I am attaching the file. Please help me if you can.

TIA
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Deploying R on the cloud - Help Please

2017-04-01 Thread Barry Rowlingson
On Fri, Mar 31, 2017 at 10:43 PM, Axel Urbiz  wrote:
> Hello,
>
> I work for a large organization who is looking to productionize (deploy)
> models built in R on the cloud. Currently, we were looking into IBM
> Bluemix, but I’ve been told only Python is supported for model deployment.
>
> I’d appreciate if anyone can point me to the right direction here in terms
> of best practices / companies that support deploying R models on the cloud.

 Where have you looked already? There's a couple of companies you
might have heard of, a little programming outfit called "Microsoft"
and a boutique database business called "Oracle" who have a bit of
expertise in R at scale. Try contacting them.

Barry

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] commercial license

2016-09-12 Thread Barry Rowlingson
Why do you want a commercial license? The software is free of charge
and free to use anywhere.

If you want support of some kind, then you need to spell this out -
there are companies and consultants who will support your R work for a
price.


On Mon, Sep 12, 2016 at 8:39 AM, benjamin.stoc...@daimler.com
 wrote:
> Dear r-project Team
>
> How does It cost a commercial license for the R Console and the R-comander 
> GUI without the Rstudio enviroment.
> Thanks for helping me.
>
>
> Freundliche Gr�sse/Kind regards
>
> Benjamin Stocker
> Reporting/Controlling MBC
> Mercedes-Benz Schweiz AG
> Bernstrasse 55
> 8952 Schlieren/Switzerland
>
> Phone +41 44 755 84 24
> Fax +41 44 755 82 17
> mailto:benjamin.stoc...@daimler.com
>
> www.mercedes-benz.ch
>
>
> If you are not the addressee, please inform us immediately that you have 
> received this e-mail by mistake, and delete it. We thank you for your support.
>
>
> [[alternative HTML version deleted]]
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] How to reach the column names in a huge .RData file without loading it

2016-03-18 Thread Barry Rowlingson
You *might* be able to get them from the raw file...

First, I don't quite know what "colnames" of an .RData file means.
"colnames" are the column names of a matrix (or data frame), so I'll
assume your .RData file contains exactly one data frame and you want
to column names of it.

So let's create one of those:


mydataframe = data.frame(mylongnamehere=runif(3),
anotherlongname=runif(3), z=runif(3), y=runif(3),
aasdkjhasdkjhaskdj=runif(3))
save(mydataframe, file="./test.RData")

Now I'm going to use some Unix utilities to see if there's any
identifiable strings in the file. .RData files are by default
compressed using `gzip`, so I'll `gunzip` them and pipe it into
`strings`:

$ gunzip -c test.RData | strings -t d
  0 RDX2
 35 mydataframe
230 names
251 mylongnamehere
273 anotherlongname
314 aasdkjhasdkjhaskdj
347 row.names
389 class
410 data.frame


  - thats found the object name (mydataframe) and most of the column
names except the short ones, which are too short for `strings` to
recognise. But if your names are long enough (4 or more chars, I
think) they'll show up.

 Of course you'll have to filter them out from all the other string
output, but they should all appear shortly after the word "names",
since the colnames of a data frame are the "names" attribute of the
data.

 If you don't have a Unix or Mac machine handy you can get these
utilities on Windows via Cygwin but that's another story...

 Barry








On Wed, Mar 16, 2016 at 3:59 PM, Lida Zeighami  wrote:
> Hi,
> I have a huge .RData file and I need just to get the colnames of it. so is
> there any way to reach the column names without loading or reading the
> whole file?
> Since the file is so big and I need to repeat this process several times,
> so it takes so long to load the file first and then take the colnames!
>
> Thanks
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] divide polygon shapefile into 3 equal areas

2016-02-29 Thread Barry Rowlingson
This probably on the limit of acceptable LOCs on this list but here goes:

makeVchopper <- function(pol){
bb = bbox(pol)
delta = (bb[2,2] - bb[2,1])/10
xmin = bb[1,1]-delta
ymin = bb[2,1]-delta
ymax = bb[2,2]+delta

choppoly = function(xmax){
readWKT(sprintf("POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))",
xmin,ymin, xmin,ymax, xmax,ymax, xmax,ymin, xmin,ymin))
}
choppoly
}

slicer <- function(pol, xmin, xmax){
bb = bbox(pol)
delta = (bb[2,2] - bb[2,1])/10
ymax = bb[2,2] + delta
ymin = bb[2,1] - delta
r = readWKT(sprintf("POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))",
xmin,ymin, xmin,ymax, xmax,ymax, xmax,ymin, xmin,ymin))
gIntersection(pol,r)
}

chop_thirds <- function(pol, fractions=c(1/3, 2/3)){
chopper = makeVchopper(pol)
bb = bbox(pol)
xmin = bb[1,1]
xmax = bb[1,2]

totalArea = gArea(pol)

chopped_area = function(x){
gArea(gIntersection(chopper(x),pol))
}

edges = lapply(fractions, function(fraction){
target = totalArea * fraction
target_function = function(x){
chopped_area(x) - target
}
uniroot(target_function, lower=xmin, upper=xmax)$root
})

xdelta = (xmax-xmin)/10
chops = matrix(c(xmin-xdelta, rep(edges,rep(2,length(edges))),
xmax+xdelta), ncol=2, byrow=TRUE)
apply(chops, 1, function(edges){
slicer(pol, edges[1], edges[2])
})

}

Usage:

library(rgeos)
library(sp)
# sample data
pol <- readWKT(paste("POLYGON((-180 -20, -140 55, 10 0, -140 -60, -180
-20),","(-150 -20, -100 -10, -110 20, -150 -20))"))
plot(pol)

# now split

parts = chop_thirds(pol)
plot(pol)
plot(parts[[1]], add=TRUE, col=1)
plot(parts[[2]], add=TRUE, col=2)
plot(parts[[3]], add=TRUE, col=3)


if not convinced:

> gArea(parts[[1]])
[1] 3375
> gArea(parts[[2]])
[1] 3375.001
> gArea(parts[[3]])
[1] 3374.999

Can easily chop into quarters too... There's some redundancy in the
code, and I'm sure it can be improved...

Barry




On Mon, Feb 29, 2016 at 6:14 PM, Boris Steipe <boris.ste...@utoronto.ca> wrote:
> Sounds like a fun little bit of code to write:
>
>  - write a function that will return the area of a slice as a function of a 
> parameter X that can vary between some bounds on your shape: left to right, 
> or top to bottom etc. E.g. if you want to slice vertically, this could be the 
> area of the part of your polygon between the leftmost point and a vertical 
> line at X. (Adapt from here perhaps: 
> https://stat.ethz.ch/pipermail/r-sig-geo/2015-July/023168.html)
>  - find the roots of that function for f(X, shape) - 1/3 * totalArea and f(X, 
> shape) - 2/3 * totalArea
>(https://stat.ethz.ch/R-manual/R-devel/library/stats/html/uniroot.html )
>
> B.
>
> On Feb 29, 2016, at 12:57 PM, Shane Carey <careys...@gmail.com> wrote:
>
>> ok thanks!!
>>
>> I would like to slice it vertically and have 3 distinct areas of equal
>> area. So I need to chop it up into 3 areas of equal size essentially.
>>
>> There is no tool to do it in QGIS!!
>>
>> Thanks
>>
>> On Mon, Feb 29, 2016 at 5:51 PM, Barry Rowlingson <
>> b.rowling...@lancaster.ac.uk> wrote:
>>
>>> On Mon, Feb 29, 2016 at 5:37 PM, Shane Carey <careys...@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> Is it possible to divide a polygon into 3 equal areas using R?
>>>
>>> Yes, in an infinite number of ways. Want to narrow it down?
>>>
>>> Specifically, you could slice it vertically, horizontally, or at any
>>> angle between. You could chop it into squares and reassign them (did
>>> you want **contiguous** areas?). You could choose a point and three
>>> radii angles that divide the polygon into 3 equal areas in an infinite
>>> number of ways.
>>>
>>> The rgeos package will help you chop polygons up, and then uniroot
>>> can find the coordinates of lines or radii of angles that chop the
>>> polygon first into 1/3 & 2/3 then chop the 2/3 into 1/2 and 1/2,
>>> giving you three equal pieces.
>>>
>>>> I cant seem to be able to do it in QGIS.
>>>
>>> If it can be done in R it can be done in Python and then it can be
>>> done in QGIS...
>>>
>>> Barry
>>>
>>
>>
>>
>> --
>> Shane
>>
>>   [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and prov

Re: [R] divide polygon shapefile into 3 equal areas

2016-02-29 Thread Barry Rowlingson
On Mon, Feb 29, 2016 at 5:37 PM, Shane Carey  wrote:
> Hi,
>
> Is it possible to divide a polygon into 3 equal areas using R?

 Yes, in an infinite number of ways. Want to narrow it down?

 Specifically, you could slice it vertically, horizontally, or at any
angle between. You could chop it into squares and reassign them (did
you want **contiguous** areas?). You could choose a point and three
radii angles that divide the polygon into 3 equal areas in an infinite
number of ways.

 The rgeos package will help you chop polygons up, and then uniroot
can find the coordinates of lines or radii of angles that chop the
polygon first into 1/3 & 2/3 then chop the 2/3 into 1/2 and 1/2,
giving you three equal pieces.

> I cant seem to be able to do it in QGIS.

 If it can be done in R it can be done in Python and then it can be
done in QGIS...

Barry

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Error opening SHP file

2016-01-22 Thread Barry Rowlingson
We can duplicate the error by giving a path to a non-existent
shapefile, which is probably the original problem:

 > require(maptools)
Loading required package: maptools
Loading required package: sp
Checking rgeos availability: TRUE
 > foo=readShapeSpatial("fnord.shp")
Error in getinfo.shape(fn) : Error opening SHP file

The error message there isn't totally explicit, and might cover a
range of other possibilities such as a corrupted shapefile, or a
missing .shx component of the shapefile or whatever.

BUT you probably shouldn't be using readShapeSpatial anyway, as it has
a habit of not reading the coordinate system in the .prj file. I find
it much easier to use `raster::shapefile` which *does* read the
coordinate system *and* gives a more explicit error message for a
missing shapefile:

 > require(raster)
Loading required package: raster
 > foo=shapefile("fnord.shp")
Error in normalizePath(x, winslash = "/", mustWork = TRUE) :
  path[1]="fnord.shp": No such file or directory

"No such file or directory"

Barry



On Fri, Jan 22, 2016 at 2:25 AM, boB Rudis  wrote:
> Agreed with the others. After finding that shapefile and getting it to
> work you are definitely not in the proper working directory.
>
> On Thu, Jan 21, 2016 at 8:40 PM, David Winsemius  
> wrote:
>>
>>> On Jan 21, 2016, at 4:39 PM, Amoy Yang via R-help  
>>> wrote:
>>>
>>> Any advice for the following errors?
>>> state.map <- readShapeSpatial("maps/st24_d00.shp")
>>> Error in getinfo.shape(fn) : Error opening SHP file
>>
>> What does list.files('maps') return? Is there a 'st24_d00.shp' value in 
>> there?
>>
>>
>> --
>> David.
>>
>>>
>>>   [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] (no subject)

2015-10-04 Thread Barry Rowlingson
lists in R can have multiple elements with the same name but if you
try and access elements by name you only get the first.

For example:

 > a = list(x=99, x=23, x=456)
 > a$x
 [1] 99

Its just the way it is.

Note you might find the `str` function useful to see the structure of R objects:

 > str(Empl)
List of 4
 $ employee: chr "Anna"
 $ family  :List of 3
  ..$ spouse: chr "Fred"
  ..$ children  : num 3
  ..$ child.ages: num [1:3] 4 7 9
 $ employee: chr "John"
 $ family  :List of 3
  ..$ spouse: chr "Mary"
  ..$ children  : num 2
  ..$ child.ages: num [1:2] 14 17
 > str(Empl[c(2,4)])
List of 2
 $ family:List of 3
  ..$ spouse: chr "Fred"
  ..$ children  : num 3
  ..$ child.ages: num [1:3] 4 7 9
 $ family:List of 3
  ..$ spouse: chr "Mary"
  ..$ children  : num 2
  ..$ child.ages: num [1:2] 14 17
 > str(Empl[c(2,4)]$family)
List of 3
 $ spouse: chr "Fred"
 $ children  : num 3
 $ child.ages: num [1:3] 4 7 9

With your current data structure you might need to use the
list-processing functions like `sapply` and `lapply` to get out the
spouse names from your list:

 > sapply(Empl[c(2,4)], function(x){x$spouse})
 family family
 "Fred" "Mary"

Keep at it!

On Sun, Oct 4, 2015 at 7:31 PM, FERNANDO MANSITO CABALLERO
 wrote:
> Dear Madam/Sir,
>
> I  am   trying to understand  R and I have come to a stumbling block. i
> have written:
>
>>Empl <- list(employee="Anna",family=list(spouse="Fred",children=3,
> +child.ages=c(4,7,9)),employee="John",family=list(spouse="Mary",children=2,
> +child.ages=c(14,17)))
>>Empl[c(2,4)]$family$spouse
> [1] "Fred"
>>#instead of [1] "Fred" "Mary"
>
> Where am I wrong?
>
> Thank you very much for your patience
> Yours truly,
> Fernando Mansito
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] names in R list's

2015-09-07 Thread Barry Rowlingson
On Mon, Sep 7, 2015 at 11:34 AM, Witold E Wolski  wrote:
> What is the access time for R lists given a name of list element, is it
> linear, log, or constant?

 Try it and see?

> Than what are to rules for names in R-lists
>
> That reusing names is possible makes me wonder.
>
> tmp <- as.list(c(1,2,3,4))
> names(tmp) = c("a","a","b","b")
> tmp
> tmp$a
>
>
> What I am looking for is a standard R data structure which will allow me
> for fast and name lookup.

 Depends what you mean by "standard"?

 There's a `hash` package that implements what are variously known as
hash tables or associative arrays (in perl) and dictionaries (in
Python)

 > require(hash)
 > z=hash("a",99)
 > z
 containing 1 key-value pair(s).
  a : 99
 > z$b=123

There's no ordering so numeric indexing fails:

 > z[1]
Error in get(k, x) : invalid first argument
 > z[[1]]
Error in z[[1]] : wrong arguments for subsetting an environment
 > z
 containing 2 key-value pair(s).
  a : 99
  b : 123

and the keys are unique, even if you try:

 > z=hash(c("a","b","b","c"), 1:4)
 > z
  containing 3 key-value pair(s).
  a : 1
  b : 3
  c : 4

I guess the lookup uses the usual fast hash lookup algorithms, but
you'd have to check the docs and source for details.

Barry

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] R command to open a file browser on Windows and Mac?

2015-08-03 Thread Barry Rowlingson
And for completeness, on linux:

system(paste0(xdg-open ,getwd()))

there's a function in a package somewhere that hides the system
dependencies of opening things with the appropriate application, and
if you pass a folder/directory to it I reckon it will open it in the
Explorer/Finder/Nautilus//xfm//This Month's Linux File Browser// as
appropriate.

But I can't remember the name of the function or the package.

Barry



On Mon, Aug 3, 2015 at 4:19 PM, Jonathan Greenberg j...@illinois.edu wrote:
 Folks:

 Is there an easy function to open a finder window (on mac) or windows
 explorer window (on windows) given an input folder?  A lot of times I want
 to be able to see via a file browser my working directory.  Is there a good
 R hack to do this?

 --j

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] API request from R

2015-02-19 Thread Barry Rowlingson
On 19 Feb 2015 20:11, Robert Baer rb...@atsu.edu wrote:


 On 2/19/2015 8:06 AM, Barry Rowlingson wrote:

 On Wed, Feb 18, 2015 at 11:44 AM, Mittal Ashra via R-help
 r-help@r-project.org wrote:

 Dear All,
 Apologies for mailing it to the whole crowd. This is Mittal, presently
working in a Project where we have build a platform for displaying
recommendations and the results are based on the statistical models.
 I have gone through the CRAN repository to look out for an package
which converts the R code into an JAVA API and that can be called from the
platform. However, did not find any. If anyone can guide me to the right
package that will be grateful.
 The packages can be similar to DeployR from Revolution Analytics.

  I doubt there's anything smart enough to take a set of R functions
 and magically create all the necessary Java boilerplate code that
 constitutes an implementation of an API in Java (cynics would say Java
 was all boilerplate...).

  There's the rJava package, which includes the JRI system for calling
 R from Java. Then your java can kick off an R engine and do R stuff:

 I thought rJava called java from R not the other way around.

 Description: Low-level interface to Java VM very much like .C/.Call and
friends. Allows creation of objects, calling methods and accessing fields.




Yes, but it includes the JRI code for calling R from Java. It's in the
package directory with some example Java programme.




   [boilerplate code deleted]

   Rengine re=new Rengine(args, false, new TextConsole());

   [more deleted boilerplate]

   re.eval(data(iris),false);

 What you would have to do would be to write the Java
 functions/methods/classes with the appropriate arguments for your API
 and make them call the R code this way.

  I think RCaller is another way of doing this from Java - its not on
 CRAN since its not an R package, its a Java library.

 Barry

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.


 --


 Robert W. Baer, Ph.D.
 Professor of Physiology
 Kirksville College of Osteopathic Medicine
 A T Still University of Health Sciences
 800 W. Jefferson St
 Kirksville, MO 63501
 rbaer(at)atsu.edu

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] API request from R

2015-02-19 Thread Barry Rowlingson
On Wed, Feb 18, 2015 at 11:44 AM, Mittal Ashra via R-help
r-help@r-project.org wrote:
 Dear All,
 Apologies for mailing it to the whole crowd. This is Mittal, presently 
 working in a Project where we have build a platform for displaying 
 recommendations and the results are based on the statistical models.
 I have gone through the CRAN repository to look out for an package which 
 converts the R code into an JAVA API and that can be called from the 
 platform. However, did not find any. If anyone can guide me to the right 
 package that will be grateful.
 The packages can be similar to DeployR from Revolution Analytics.

 I doubt there's anything smart enough to take a set of R functions
and magically create all the necessary Java boilerplate code that
constitutes an implementation of an API in Java (cynics would say Java
was all boilerplate...).

 There's the rJava package, which includes the JRI system for calling
R from Java. Then your java can kick off an R engine and do R stuff:

  [boilerplate code deleted]

  Rengine re=new Rengine(args, false, new TextConsole());

  [more deleted boilerplate]

  re.eval(data(iris),false);

What you would have to do would be to write the Java
functions/methods/classes with the appropriate arguments for your API
and make them call the R code this way.

 I think RCaller is another way of doing this from Java - its not on
CRAN since its not an R package, its a Java library.

Barry

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Interview questions?

2015-01-11 Thread Barry Rowlingson
Ask if they have a favourite R programmer. This will tell you how much into
the R culture they are, and perhaps also tell you if their opinions of a
good programmer concur with yours...
On 11 Jan 2015 16:49, Keith S Weintraub kw1...@gmail.com wrote:

 Folks,

 I was wondering if anyone has put together a list of R job interview
 questions?

 I’m thinking of about 5-20 possibly open ended questions for interviewing
 a candidate to do R programming. Just programming. Not statistics or
 mathematics.

 What I don’t want are tricky “puzzles” that are more about how clever the
 interviewer questions are than how to get the best person for the job.

 I would consider myself a mid-level R programmer so this would also be a
 great opportunity to learn more and be able to hire a great candidate.

 I am perfectly happy to get a reference, book title or URL.

 Not looking for anyone to do my work for me!

 Best to all,
 Happy New Year,
 KW

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] number of individuals where X=0 during all periods (longitudinal data)

2014-12-23 Thread Barry Rowlingson
obligatory dplyr solution:

library(dplyr)
 zeroes = Test %% group_by(ID) %% summarise(Zs=all(X==0))

 - that gives you a data frame of unique ID and Zs==TRUE if that ID
has all zeroes. With that you just sum(zeroes$Zs) to get the total
number with all zeroes. Or add %% filter(Zs) %% nrow() to the
pipeline to get it directly.

Its well worth learning a bit about the dplyr and tidyr package,
especially if you have a lot of things you might want to do by ID in a
data frame.

Barry




On Mon, Dec 22, 2014 at 7:52 PM, William Dunlap wdun...@tibco.com wrote:
 Another approach to to make a table and extract your summaries from the
 table:

tbl - with(Test, table(ID, IsZero=X==0))
tbl
  IsZero
   ID  FALSE TRUE
 1 31
 2 02
 3 03
sum(tbl[,FALSE] == 0)
   [1] 2
sum(tbl[,FALSE] == 0  rowSums(tbl)=3)
   [1] 1

 Remove the calls to sum() from those expressions and you will see which
 ID's satisfy the conditions.



 Bill Dunlap
 TIBCO Software
 wdunlap tibco.com

 On Mon, Dec 22, 2014 at 10:54 AM, Chel Hee Lee chl...@mail.usask.ca wrote:

  tmp - split(Test, Test$ID)
 
  # number of subjects with X=0 (all periods)
  x - lapply(tmp, function(x) all(x$X ==0))
  length(x[unlist(x)])
 [1] 2
 
  # number of subjects with X=0 (at least three weeks)
  x - lapply(tmp, function(x) sum(x$X==0)=3)
  length(x[unlist(x)])
 [1] 1
 

 Is this what you are looking for?  I hope this helps.

 Chel Hee Lee

 On 12/22/2014 7:45 AM, najuzz wrote:

 #Hi guys,

 #I would like to count the number of individuals that receive X=0
 troughout
 their observational period.
 #example dataset:

 ID-c(1,1,1,1,2,2,3,3,3)
 X-c(0,1,2,1,0,0,0,0,0)
 Time-c(1,2,3,4,1,2,1,2,3)
 Test-data.frame(ID,X,Time)

 # Individuals 2 and 3 have x=0 during all their periods. The count should
 hence equal to two. I simply have
 # no clue how R could solve this for me. As an addon, I would also like to
 know the number of individuals  #that report X=0 during all periods plus
 have at least 3 weeks of observations. The answer would be one in #this
 sample datset.

 #Thank you



 --
 View this message in context: http://r.789695.n4.nabble.com/
 number-of-individuals-where-X-0-during-all-periods-
 longitudinal-data-tp4701023.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.


 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.


 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Count number of Fridays in a month

2014-10-10 Thread Barry Rowlingson
Or try this:

fridays - function(the_day){
require(lubridate)
day(the_day) = 1
the_month = seq(the_day, the_day+months(1)-days(1),1)
sum(wday(the_month) == 6)
}

That returns the number of Fridays in the month of a Date object given as arg:

 fridays(as.Date(2012-01-01))
[1] 4
 fridays(as.Date(2012-02-01))
[1] 4
 fridays(as.Date(2012-03-01))
[1] 5
 fridays(as.Date(2012-04-01))
[1] 4

Then you can build a function to compute the friday count ratio
between the month of a date and the previous month, given a data in
that string format you specified (d-m-y)

friday_ratio- function(dayX){
require(lubridate)
the_day = as.Date(dmy(dayX))
day(the_day)=1
the_prev_month = the_day
month(the_prev_month) = month(the_day)-1
nf_current = fridays(the_day)
nf_prev = fridays(the_prev_month)
nf_current/nf_prev
}

 friday_ratio(31-may-2014)
[1] 1.25
 friday_ratio(1-may-2014)
[1] 1.25
 friday_ratio(1-jun-2014)
[1] 0.8
 friday_ratio(1-jul-2014)
[1] 1
 friday_ratio(1-aug-2014)
[1] 1.25

it is left as an exercise to convert this to the +1/0/-1 value - I
think the abs function may help...

Also, an exercise is to vectorise this over a vector of string dates.




On Fri, Oct 10, 2014 at 1:16 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 10/10/2014 8:10 AM, Abhinaba Roy wrote:
 Hi Duncan,

 I have converted the string to a POSIXIt object using

  strptime('31-may-2014',format=%d-%b-%Y)

 But could not figure out the way forward.

 Could you please elaborate a bit?

 Try this:

 ?POSIXlt

 Duncan Murdoch


 On Fri, Oct 10, 2014 at 5:14 PM, Duncan Murdoch
 murdoch.dun...@gmail.com mailto:murdoch.dun...@gmail.com wrote:

 On 10/10/2014, 7:28 AM, Abhinaba Roy wrote:
  Hi R helpers,
 
  I want to write a function which will
 
  1. Count the number of fridays in the current month ( to extract
 month from
  given date) and also the number of fridays in the preceeding month
 
  2. Calculate the ratio of the number of fridays in current month
 to the
  number of fridays in the precceding month
 
  3. Return a integer value calculated as
  ifelse(ratio1,1,ifesle(ration1,-1),0)
 
  The date which is passed is in the format *'31-may-2014'*
 
  So, given the date '31-may-2014'
 
  Number of fridays in May2014 = 5
  Number of fridays in Apr2014 = 4
 
  Ratio = 5/4 1
  Hence, the function will return a value 1
 
  I want to call the function by passing '31-may-2014' as an argument
 
  How can this be done in R?
 
  Any help will be appreciated

 Convert your string to a POSIXlt object using as.POSIXlt.  Then
 you can
 extract year, month and weekday from the result, and go from there.
 (The only unobvious part is figuring out how many days are in each
 month, but there are questions online giving various ways to do this.)

 Duncan Murdoch



 __
 R-help@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.

__
R-help@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.


Re: [R] Parliament Seats Graph

2014-09-12 Thread Barry Rowlingson
On Fri, Sep 12, 2014 at 11:25 AM, Jim Lemon j...@bitwrit.com.au wrote:

 I can see how you would plot the points going from right to left (the easy
 way), by plotting the next point on the arc with the least increase in
 angle from the last point plotted. If this is the way you have worked out, I
 think all that you have to do is to turn the party affiliation into a factor 
 (if
 it is not already) and plot the points by the sorted numeric value of the
 factor. You will probably want to adjust the levels to some political
 dimensions before doing the sort.

 I'm interested in how you get exactly N seats in M rows that look as
neat as that. My eyes are going funny trying to count the dots in each
arc but there must be some nice algorithm for generating a sequence
that sums to N, has M elements, and has a small variable difference
between the row sizes to constrain the sum...

 Or am I overthinking this?

Barry

__
R-help@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.


Re: [R] Parliament Seats Graph

2014-09-12 Thread Barry Rowlingson
I've generalised Duncan's code:

seats - function(N,M, r0=2.5){
radii - seq(r0, 1, len=M)

counts - numeric(M)
pts = do.call(rbind,
lapply(1:M, function(i){
counts[i] - round(N*radii[i]/sum(radii[i:M]))
theta - seq(0, pi, len = counts[i])
N - N - counts[i]
data.frame(x=radii[i]*cos(theta), y=radii[i]*sin(theta), r=i,
theta=theta)
}  )
)
pts = pts[order(-pts$theta,-pts$r),]
pts
}


and written this:

election - function(seats, counts){
stopifnot(sum(counts)==nrow(seats))
seats$party = rep(1:length(counts),counts)
seats
}


sample usage:

 layout = seats(449,16)
 result = election(layout, c(200,200,49)) # no overall majority!!!
 plot(result$x, result$y, col=result$party,pch=19, asp=1)

Looks like a start...


On Fri, Sep 12, 2014 at 12:41 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 12/09/2014, 7:18 AM, Barry Rowlingson wrote: On Fri, Sep 12, 2014 at
 11:25 AM, Jim Lemon j...@bitwrit.com.au wrote:

 I can see how you would plot the points going from right to left (the
 easy
 way), by plotting the next point on the arc with the least increase in
 angle from the last point plotted. If this is the way you have worked
 out, I
 think all that you have to do is to turn the party affiliation into a
 factor (if
 it is not already) and plot the points by the sorted numeric value of the
 factor. You will probably want to adjust the levels to some political
 dimensions before doing the sort.

  I'm interested in how you get exactly N seats in M rows that look as
 neat as that. My eyes are going funny trying to count the dots in each
 arc but there must be some nice algorithm for generating a sequence
 that sums to N, has M elements, and has a small variable difference
 between the row sizes to constrain the sum...

  Or am I overthinking this?

 I would guess it's something like this:

 1.  Set the radii of each arc.  Since the spacing of the dots looks
 even, the number of dots in each arc should be proportional to the radius.

 2.  Using the proportions above find the number of dots in the largest
 arc by rounding the proportion times total to an integer.

 3.  Repeat for each arc moving inwards, subtracting the number of dots
 already shown from the grand total.

 The same scheme can be used to set the number of dots of each colour in
 each arc.

 For example:

 radii - seq(2.5, 1, len=11)
 N - 449
 counts - numeric(11)
 plot(c(-2.5, 2.5), c(0, 2.5), type=n, axes=FALSE, asp=1)
 for (i in 1:11) {
   counts[i] - round(N*radii[i]/sum(radii[i:11]))
   theta - seq(0, pi, len = counts[i])
   points(radii[i]*cos(theta), radii[i]*sin(theta))
   N - N - counts[i]
 }

 Duncan Murdoch


__
R-help@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.


Re: [R] Parliament Seats Graph

2014-09-12 Thread Barry Rowlingson
Note if you are trying to compare parliament diagrams created with
this code with images from wikipedia, the wikipedia images I tried are
wrong.

The Ukrainian one: http://en.wikipedia.org/wiki/Verkhovna_Rada  shows
two groups in red but the legend only has one red party, and the
French Senate: http://en.wikipedia.org/wiki/French_Parliament has 21
red Communist dots but the text says 20. It also has 10 green
(Green) dots but the text says 12.

Maybe wikipedia would like to use this code to generate these diagrams
from the data!





On Fri, Sep 12, 2014 at 1:01 PM, Rowlingson, Barry
b.rowling...@lancaster.ac.uk wrote:
 I've generalised Duncan's code:

 seats - function(N,M, r0=2.5){
 radii - seq(r0, 1, len=M)

 counts - numeric(M)
 pts = do.call(rbind,
 lapply(1:M, function(i){
 counts[i] - round(N*radii[i]/sum(radii[i:M]))
 theta - seq(0, pi, len = counts[i])
 N - N - counts[i]
 data.frame(x=radii[i]*cos(theta), y=radii[i]*sin(theta), r=i,
 theta=theta)
 }  )
 )
 pts = pts[order(-pts$theta,-pts$r),]
 pts
 }


 and written this:

 election - function(seats, counts){
 stopifnot(sum(counts)==nrow(seats))
 seats$party = rep(1:length(counts),counts)
 seats
 }


 sample usage:

 layout = seats(449,16)
 result = election(layout, c(200,200,49)) # no overall majority!!!
 plot(result$x, result$y, col=result$party,pch=19, asp=1)

 Looks like a start...


 On Fri, Sep 12, 2014 at 12:41 PM, Duncan Murdoch
 murdoch.dun...@gmail.com wrote:
 On 12/09/2014, 7:18 AM, Barry Rowlingson wrote: On Fri, Sep 12, 2014 at
 11:25 AM, Jim Lemon j...@bitwrit.com.au wrote:

 I can see how you would plot the points going from right to left (the
 easy
 way), by plotting the next point on the arc with the least increase in
 angle from the last point plotted. If this is the way you have worked
 out, I
 think all that you have to do is to turn the party affiliation into a
 factor (if
 it is not already) and plot the points by the sorted numeric value of the
 factor. You will probably want to adjust the levels to some political
 dimensions before doing the sort.

  I'm interested in how you get exactly N seats in M rows that look as
 neat as that. My eyes are going funny trying to count the dots in each
 arc but there must be some nice algorithm for generating a sequence
 that sums to N, has M elements, and has a small variable difference
 between the row sizes to constrain the sum...

  Or am I overthinking this?

 I would guess it's something like this:

 1.  Set the radii of each arc.  Since the spacing of the dots looks
 even, the number of dots in each arc should be proportional to the radius.

 2.  Using the proportions above find the number of dots in the largest
 arc by rounding the proportion times total to an integer.

 3.  Repeat for each arc moving inwards, subtracting the number of dots
 already shown from the grand total.

 The same scheme can be used to set the number of dots of each colour in
 each arc.

 For example:

 radii - seq(2.5, 1, len=11)
 N - 449
 counts - numeric(11)
 plot(c(-2.5, 2.5), c(0, 2.5), type=n, axes=FALSE, asp=1)
 for (i in 1:11) {
   counts[i] - round(N*radii[i]/sum(radii[i:11]))
   theta - seq(0, pi, len = counts[i])
   points(radii[i]*cos(theta), radii[i]*sin(theta))
   N - N - counts[i]
 }

 Duncan Murdoch


 __
 R-help@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.

__
R-help@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.


Re: [R] Operator proposal: %between%

2014-09-05 Thread Barry Rowlingson
On Fri, Sep 5, 2014 at 12:28 AM, David Winsemius dwinsem...@comcast.net wrote:

 If you are accepting feature requests

The R issue tracker has a wishlist section:

https://bugs.r-project.org/bugzilla3/buglist.cgi?component=Wishlistorder=changeddate%20DESC%2Cbug_status%2Cpriority%2Cassigned_to%2Cbug_idproduct=Rquery_based_on=query_format=advancedresolution=---

 - dream on

 I would like to see a `%btwn%` function that would accept as its second 
 argument either a two element numeric or alpha vector or a two column matrix 
 of with the same number of rows as the first argument. Something along these 
 lines:


 `%btwn%` - function(x,y) if(!is.null(dim(y))dim(y)[1] == length(x) ){x = 
 y[,1]  x  y[,2]}else{x = y[1]  x y[2]}
 4 %btwn% c(2,6)
 [1] TRUE

The problem with wishes is that someone has to make them come true, in
this case R-core. And unlike a genie who grants your wish and then
jumps back in his bottle, R-core are nice enough to hang around in
case your wish doesn't quite go to plan. They have to keep your wish
up to date, make sure it doesn't conflict with anyone elses wishes and
so on (probably taken this analogy too far now...).

 So Duncan's unspoken subtext is why not put this in a package and
submit it to CRAN?. And then you maintain it. Because after all, you
wrote it.

 My additional question is Why are things like %% hidden away inside
the TeachingDemos package?. Is it worth collating useful %operators%
into a new package?

 I can't see the point really since in about a year or two everyone
will just think A %foo% B is some kind of foo-pipe that pipes A into
B...

Barry

__
R-help@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.


Re: [R] How to get source code of a package

2014-09-05 Thread Barry Rowlingson
On Fri, Sep 5, 2014 at 8:01 AM, madhvi.gupta madhvi.gu...@orkash.com wrote:
 Hi,
 Can anyone tell me how to get  source code of a package of R?
 I want to integrate elastic search with R if there is any way please let
 me know or give me a direction to do that.

Which R packages do you want source code for? I should think that
source code of other ElasticSearch API clients would be useful,
particularly those languages that are most like R in style, such as
Python or Ruby.

 However if you google for Elastic Search API Client R you'll find this:

https://github.com/ropensci/elastic

 which is a start. That's assuming you are talking about a client-side
elastic search package for R, and not somehow integrating it into the
server

Barry


 Thanks.

 [[alternative HTML version deleted]]

 __
 R-help@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.

__
R-help@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.


Re: [R] loading saved files with objects in same names

2014-08-20 Thread Barry Rowlingson
On Tue, Aug 19, 2014 at 1:30 AM, Jinsong Zhao jsz...@yeah.net wrote:
 Hi there,

 I have several saved data files (e.g., A.RData, B.RData and C.RData). In
 each file, there are some objects with same names but different
 contents. Now, I need to compare those objects through plotting.
 However, I can't find a way to load them into a workspace. The only
 thing I can do is to rename them and then save and load again.

 Is there a convenient to load those objects?

 Thanks a lot in advance.

The technique of loading into an environment already mentioned can be
cleaned up and put into a function.

First lets save a thing called x into two files with different values:

  x=first
  save(x,file=f.RData)
  x=second
  save(x,file=s.RData)

This little function wraps the loading:

  getFrom=function(file, name){e=new.env();load(file,env=e);e[[name]]}

So now I can get 'x' from the first file - the value is returned from
`getFrom` so I can assign it to anything:

  x1 =  getFrom(f.RData,x)
  x1
[1] first
  x2 = getFrom(s.RData,x)
  x2
[1] second

And I can even loop over RData files and read in all the `x`s into a vector:

  sapply(c(f.RData,s.RData),function(f){getFrom(f,x)})
  f.RData  s.RData
  first second

(on second thoughts, possibly 'loadFrom' is a better name)

Barry

__
R-help@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.


Re: [R] R License

2014-05-26 Thread Barry Rowlingson
On Sat, May 24, 2014 at 4:11 PM, Juan Ulises Bohorquez Carvajal
juan.bohorq...@ecopetrol.com.co wrote:
 Thanks, could you send to me an official certificate in pdf with this 
 information? Or a certified email to support the information license?

And what would be the authority that supplies such a certificate? R is
not the proprietary property of a company or person, so I don't think
a body exists that could supply such an authoritative email.

What does (or should) exist are the comments in the source files
explaining the license terms, and this is echoed in the banner message
on startup.

I'm sure if you asked very nicely you could get a letter from someone
held in high esteem by the R community - some professor at an ancient
university perhaps - stating their belief that you can use R for your
company in accordance with the licenses. But that would just be
repeating what you've already heard here. The licensing is with the
code, and clearly stated.

Other, larger companies use R extensively - see this recent blog entry:

http://blog.revolutionanalytics.com/2014/05/companies-using-r-in-2014.html

Note in particular the banner when R starts: ABSOLUTELY NO WARRANTY
- which means if a bug in R makes one of your gas processing plants
explode, there's probably nobody to sue - but if you read the small
print on proprietary software licenses you'll probably find similar
terms anyway. R puts it out there in block capitals every time.

Barry

 __
 R-help@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.

__
R-help@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.


Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Barry Rowlingson
On Fri, May 16, 2014 at 4:46 PM, Witold E Wolski wewol...@gmail.com wrote:
 Dear Jari,

 Thanks for your reply...

 The overhead would be
 2 for loops
 for(i in 1:dim(x)[2])
 for(j in i:dim(x)[2])

 isn't it? Or are you seeing a different way to implement it?

 A for loop is pretty expensive in R. Therefore I am looking for an
 implementation similar to apply or lapply were the iteration is made
 in native code.

No, a for loop is not pretty expensive in R -- at least not compared
to doing a k-s test:

  system.time(for(i in 1:1){ks.test(runif(100),runif(100))})
   user  system elapsed
  3.680   0.012   3.697

 3.68 seconds to do 1 ks tests (and generate 200 runifs)

  system.time(for(i in 1:1){})
   user  system elapsed
  0.000   0.000   0.001

 0.000s time to do 1 loops. Oh lets nest it for fun:

  system.time(for(i in 1:100){for(i in 1:100){ks.test(runif(100),runif(100))}})
   user  system elapsed
  3.692   0.004   3.701

 no different. Even a ks-test with only 5 items is taking me 2.2 seconds.

Moral: don't worry about the for loops.

Barry

__
R-help@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.


Re: [R] Making a trial based Package for 30-days.

2014-05-12 Thread Barry Rowlingson
On Mon, May 12, 2014 at 10:31 AM, Ashis Deb ashisde...@gmail.com wrote:
 Hi  all   ,


I have   a  GUI  package , which  I  want  to  make  it
 work  for  a  certain period,say-30days   ,after which  it should  be self
 destructive  .

 Could it  be possible  ??


 Yes.

 But why bother? Can you stop people:

 a) turning back the clock on their PCs?
 b) reinstalling again after 30 days?
 c) installing on a fresh operating system?
 d) editing the program to remove the date check?

You have to decide if the effort in preventing all these things is
worth it. Unless your software is really going to make you millions of
dollars unless you do this, the answer is no.

 Easiest option is to just pop up a nag screen saying You really
should stop using this after 30 days, but don't bother trying to
enforce it (and definitely don't go deleting it itself, you'll end up
deleting someone's files and then they will sue you).

 With a nag screen, people who are going to buy your product will buy
it, people who aren't going to buy your product will carry on using
it, but then they are going to do that anyway since these measures are
so easily circumvented. Unless you want to invest in some serious
licensing infrastructure.

Barry

__
R-help@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.


Re: [R] Making a trial based Package for 30-days.

2014-05-12 Thread Barry Rowlingson
On Mon, May 12, 2014 at 1:11 PM, Ashis Deb ashisde...@gmail.com wrote:
 Well  it's  the company requirement to do  so  ,  and  give it on  a trial
 basis  to  client to check , if they  like they  will BUY  or  it will  self
 destruct itself ,

 No, if they like it they will BUY or they will CIRCUMVENT your
self-destruction mechanism.

 The company requirement has not been thought through to
practicalities, and is unrealistic, and is not constrained by
limitation. How do you prevent them re-installing?

 For a price, I will fly (first class) to all your clients after 30
days and delete the software for you.

Barry

__
R-help@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.


Re: [R] Making a trial based Package for 30-days.

2014-05-12 Thread Barry Rowlingson
On Mon, May 12, 2014 at 3:45 PM, Spencer Graves
spencer.gra...@structuremonitoring.com wrote:

One company I know installed an S-Plus or R package only on
 servers, so their customers had to use it on a server.  (In this case,
 the customers had a GUI and may not have known that it was S-Plus or R
 behind it.)  This company also developed techniques for encrypting their
 code.  I don't think it was perfect, and they eventually wrote it in C
 or C++ or Matlab.

 If the code runs on a server controlled by the company, and the user
uses the code via some network API, then it might be practical to give
a user a password that is revoked after thirty days. If the server is
controlled by the user, then all bets are off.

 Any encrypted code has to be decrypted in order to be executed, so
it is only obfuscated code. Even systems where the decryption keys are
hidden in hardware chips covered in resin have been cracked by
enthusiasts with a sharp blade, small probes, and a digital
oscilloscope. We are talking hardware encryption/DRM systems developed
by companies like SONY.

So part of the answer is you can write part of your package in a
 compiled language.  That part can check your web site to check the date
 and other things.

 Still easily circumventable (poke the code, preload a different date
library DLL, turn the clock back...), so why bother? You can't
consider how you'd have self-destructing code without having a debate
about the cost and effort you want to put in and the cost and effort
crackers want to put in. I the SONY case (or similar) crackers will
compete like mad to crack the DRM, even if only for fame and not
fortune or free access to pirated games.

 I think it would take me under an hour to write a package that
self-destructed. Its not difficult, you create a file somewhere when
the system first runs, then on subsequent runs check the date is less
than 30 days after the file, and run file.remove over the package if
its expired.

Barry

__
R-help@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.


Re: [R] as.character(quote(x$y) ) = $ x y not x$y?

2014-05-10 Thread Barry Rowlingson
On Fri, May 9, 2014 at 10:42 PM, Hadley Wickham h.wick...@gmail.com wrote:
 Beware of the is.* functions:

 * is.object() does not test the usual definition of objects
 * is.vector() does not test the usual definition of vectors
 * is.numeric() does not work the same way as is.character() or is.integer()
 * is.Date() doesn't exist
 * is.nan() doesn't return TRUE for some NaNs

 Can we have an is.is function that tells us these things?

  is.is(is.object)
   [1] FALSE
Warning: is.object() does not test the usual definition of objects

  is.is(is.is)
   [1] TRUE

 For further exploration, demo(is.things) creates a handy is.ALL
function that outputs the result of running a lot of is.X functions on
its argument.

Barry

__
R-help@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.


Re: [R] R and GML data from the Canadian Goverment

2014-05-02 Thread Barry Rowlingson
You want to have a look at the R Spatial Task View for starters...

GML files can be read by the rgdal package's readOGR function. But be
warned GML is a complex beast.

For example, I downloaded canvec_gml_AB_EN.zip from that site, it unzips to
a GML (and an xsd) with a lot of layers, some of which aren't spatial.

Using the ogrinfo command line tool from the gdal library I can see the
layers:

$ ogrinfo -so AB_EN.gml
Had to open data source read-only.
INFO: Open of `AB_EN.gml'
  using driver `GML' successful.
1: d_y_n (None)
2: d_y_n00 (None)
3: d_y_n01 (None)
4: d_y_n02 (None)
5: d_y_n03 (None)
6: d_y_n04 (None)
7: d_y_n05 (None)
8: d_y_n06 (None)
[etc etc]
191: d_y166 (None)
192: d_y167 (None)
193: EN_1360049_0 (Multi Point)
194: EN_1360059_2 (Multi Polygon)
195: EN_1360049_2 (Multi Polygon)
196: EN_1340009_0 (Multi Point)
197: EN_1360059_0 (Multi Point)
198: EN_2170009_0 (Multi Point)
199: EN_1120009_1 (Multi Line String)
200: EN_1180009_1 (Multi Line String)

So thats 192 non-spatial layers and a bunch of points n lines n polygons
layers. Let's read one:

m = readOGR(./AB_EN.gml,EN_1360059_2)
plot(m)

 makes a map. Its a bunch of very small polygons, hard to see really!

Further questions will be welcome at the R-sig-geo mailing list, where we
whine about file formats on a daily basis.

Barry




On Thu, May 1, 2014 at 11:26 PM, jcrosbie ja...@crosb.ie wrote:

 I'm trying to create a map of transmission lines in Alberta. In addition,
 I'm
 very new to creating maps.

 The data can be found at: http://geogratis.gc.ca/site/eng/download


 http://ftp2.cits.rncan.gc.ca/pub/canvec/doc/CanVec_distribution_formats_en.pdf

 Would someone be able to point me in the right direction? I haven't been
 able to find an R package which is able to work with the GML data on the
 webset.  Does anyone know of which package I should use and a good example
 out there?

 Thank you



 --
 View this message in context:
 http://r.789695.n4.nabble.com/R-and-GML-data-from-the-Canadian-Goverment-tp4689843.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ignore escape characters in a string...

2014-04-08 Thread Barry Rowlingson
On Tue, Apr 8, 2014 at 4:00 PM, Jonathan Greenberg j...@illinois.eduwrote:

 C:\Program Files\R\R-3.0.3


Does R on windows have clipboard support? I can do this on Linux:

  readLines(file(clipboard))
[1] C:\\Program Files\\R\\R-3.0.3

- that's from a copy of a path with only single slashes in. But
help(connections) on my linux system doesn't mention the Windows
clipboard

Some ppl on SO have assorted solutions involving Windows scripting tools
that tweak the clipboard so you can Ctrl-V a modified value:

http://stackoverflow.com/questions/1407238/relief-from-backslash-irritation-in-r-for-windows

Barry

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ignore escape characters in a string...

2014-04-08 Thread Barry Rowlingson
On Tue, Apr 8, 2014 at 4:30 PM, Frede Aakmann Tøgersen fr...@vestas.comwrote:


 I'm a bit surprised about the \\ on a linux OS. I'm also surprised that in
 a file manager on Windows you can paste e.g. C:/users/frtog/Desktop and it
 can find its way to the folder. Weird.


 Well, the clipboard contained a path separated by single backslashes. R
read that (via the file(clipboard)) and correctly read single
backslashes. Its only when printed out that R 'escapes' them as
double-backslashes - there's really only one character there.

 What R seems to lack is 'raw string'  functionality. In python you do this
with a string quote prefix, for example 'r':

  len(\t)
 1

 In that case the \t is interpreted as a single character, \t, or tab. Add
the r modifier:

 len(r\t)
2

and now you get two characters, backslash and t.

You'll often see regular expressions in Python using raw strings since they
tend to contain slashes and backslashes which you really want in there.

Barry

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Data file verification protocol

2014-03-19 Thread Barry Rowlingson
On Wed, Mar 19, 2014 at 4:03 AM, Wolf, Steven wolfs...@msu.edu wrote:

 Hi R users,

 This isn't a R-specific issue, per-se, but I thought that this list would
 have some helpful input on this topic.  First, a bit of background.  I am
 working on a project which is interested in following approx 1000 students
 each semester, and collects about 15 different measurements about each
 student.  These are both numeric and text, for example grades in a course,
 race, gender, etc.

 I am looking for a verification protocol which can look at a data file and
 see if it has been modified.  Ideally, this should be something that I can
 check the file with to see if the file has been changed or corrupted and
 incorporate into my analysis workflow.  (i.e., every time I look at my
 data, I can run this protocol to ensure the file hasn't changed.)


 Operating systems will keep the last modification time of a file, and you
can use the file.info function in R to check that. However, if someone just
opens and re-saves the file without changing it that will usually trigger
an update of the modification time.

 The big question you haven't answered is has the file been changed since
when?. Since you last ran your analysis? This then looks like a job for
the 'make' utility. You specify rules in a 'Makefile' that specify how to
create targets based on dependencies. For example:

results.txt: data.dat process.R
Rscript process.R

- says that results.txt depends on data.dat (your input data) and
process.R (your R code that creates results.txt from data.dat), and would
run Rscript process.R if data.dat or process.R have a newer modification
time than results.txt. Run twice in rapid succession, this makefile
wouldn't run R the second time because results.txt would be newer then its
dependencies since it was just created.

 Objects within R don't have timestamps, so its not possible to
conditionally run an R function if its parameter objects are newer than the
result object. But if you save R objects as .RData files, you can use
make based on the timestamps of the .RData files.

 Alternatively you can just keep recent versions of the file hanging around
(1000x15 is pretty small, even multiplied by another 1000 is still not
exactly Big Data) and compare them. In a unix environment the cmp command
will quickly test two files for equality, or if you don't want to store
copies of your file you simply compute a checksum or digest and compare
digests. In a unix environment you'd typically use the md5sum command
which spits out a 128-bit (32 character) checksum for its arguments. If the
checksum is different, then the file is different.

 Your use case is still a bit vague - for example you haven't said what the
file format is, or how its being updated.

Barry

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] regular pentagon

2014-03-09 Thread Barry Rowlingson
On Sun, Mar 9, 2014 at 5:11 AM, Rolf Turner r.tur...@auckland.ac.nz wrote:

 On 08/03/14 10:22, Yuanzhi Li wrote:
  Hello, everyone,
 
  Do you have any idea to get a set of random points within a regular
  pentagon? Thanks in advance!

 You can easily do this using the spatstat package.


 Or with sines, cosines, and 72 degrees. Generate points in a triangle and
apply a random (0,4) integer multiple of 72 rotation

 Never mind asking us if we have any idea, do you (original poster) have
any idea?

Barry

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] creating an equivalent of r-help on r.stackexchange.com ? (was: Re: Should there be an R-beginners list?)

2014-02-05 Thread Barry Rowlingson
On Wed, Feb 5, 2014 at 6:32 AM, Liviu Andronic landronim...@gmail.com wrote:

 So in the end my proposal is not necessarily for r-help to go to SE,
 but more for R to have its own QA forum/wiki for helping R users.
 This could perfectly take the form of setting up its own open-source
 https://github.com/ialbert/biostar-central QA interface (a SE-like
 web interface) on R Core's servers. In this case the website would
 look like the following: http://www.biostars.org/ .

 Have you seen Field Of Dreams? Kevin Costner builds a baseball
stadium in the middle of nowhere and all his favourite baseball stars
appear out of the corn. He does it because he hear a voice say if you
build it, they will come.

 R-core are not going to do anything for users. They are primarily, if
I recall one of Brian Ripley's talks correctly, doing it for
themselves. Quite right too.

R Core doesn't have servers - at least not ones they can just dedicate
to running and maintaining a Q+A site, especially one that could scale
up massively. That requires money for hardware or cloud servers, admin
time, sys maintenance time etc.

So if you think something is a good idea, build it, and they (the
users) will come. For example, I don't go to the r-project site for
help any more. www.rdocumentation.org has a much nicer search
interface. Someone started asking questions with the [R] tag on
StackOverflow, and now a lot of people hang around there. The RStudio
guys didn't whine on R-Core to build a nice user interface - they
built it, and look what happened.

Let's leave R-Core to carry on with the core, and let the community
build around it. If you can raise the cash to fund an amazon server
for a year that can run one of the StackExchange clones, and are
willing to admin it, then you can surely advertise it here and if
people like it they will come. Maybe you can build a business model
round advertising, consulting, or premium Q+A services (these exist:
my gf gets paid to answer what are probably homework questions...) to
keep it going. If you can't then you should appreciate what you just
asked R-Core to do for nothing.

Barry

__
R-help@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.


Re: [R] creating an equivalent of r-help on r.stackexchange.com ?

2014-02-03 Thread Barry Rowlingson
As one of the original ranters of hey lets move to StackOverflow a
few years back (see my UseR! lightning talk from Warwick) I should
probably stick my oar in.

I don't think the SO model is a good model for all the discussions
that go on on R-help.

I think SO is a good model for questions that have fairly precise
answers that are demonstrably 'correct'.

I think a mailing list is a bad model for questions that have answers.
Reasons? Well, I see an email thread, start reading it, eight messages
in, somewhere in a mix of top-posted and bottom-posted content, I
discover the original poster has said Yes thanks Rolf that works!.
Maybe I've learnt something in that process, but maybe I had the
answer too and I've just wasted my time reading that thread. With
StackOverflow questioners accept an answer and you needn't waste
time reading it. I've given up reading R-help messages with
interesting question titles if there's more than two contributors and
six messages, since its either wandered off-topic or been answered. I
suspect that heuristic is less efficient than SO's answer accepted
flag.

SO questions are tagged. I can look at only the ggplot-tagged
questions, or the 'spatial'-tagged questions, or ignore anything with
'finance' in it. Mailing lists are a bit coarse-grained and rigid for
that, and subject lines are often uninformative of the content.

SO is smart. Users are dumb, right? How many R-help questions could
have been answered by googling or reading the documentation? SO
compares input questions with existing questions, and suggets to users
that maybe this question here has the answer. How cool is that? And
the more questions and answers it has, the smarter that system gets.
Duplicate questions can be manually flagged by moderators.

SO questions get edited by other users, including fixing typos and
tagging properly. And bad questions are moderated out of existence, so
you don't even see them. How would you like to never see an R FAQ 7.31
question ever again?

For general discussion of R-related topics I think R-help is a better
place than SO but please don't make the mistake of thinking SO is just
another web-forum which those pesky kids on my lawn are promoting
instead of my cuddly old mailing list. Its a brilliant
question-and-answer *service*, which could not work as well as it does
over email.

 I also don't think a specialised R StackExchange site would be a good
idea either, since the site software is not suited to discussions and
the site would just fill with rambling guff.

 In summary: got an R programming question that you think has a
definite answer? Post to SO. Want to ask something for discussion,
like what options there are for doing XYZ in R, or why lm() is faster
than glm(), or why are these two numbers not equal - post to R-help.
Questions like that do get posted to SO, but we mod them down for
being off-topic and they disappear pretty quickly.

 Personally I still don't like mailing lists for discussions, but
StackExchange sites are not the place for discussion and I'm not sure
a better place exists that would keep everyone happy anyway!




On Mon, Feb 3, 2014 at 9:49 PM, Ted Harding ted.hard...@wlandres.net wrote:
 Ditto. And ditto. And (by the way -- no-one seems to have mentioned it)
 what are the possibilities, for mail appearing on something like Stack
 Exchange, of having the mail sent to oneself so that it can be stored
 locally, on one's own machine? That is the only way I would want to
 work -- anything interesting is sitting in my disk, I can edit it if
 I wish, I can make local copies, etc. etc. etc. etc. Anything which is
 not interesting gets deleted (though I can always dig into R-help
 archives if need be).

 Best wishes,
 Ted.

 On 03-Feb-2014 21:36:21 Rolf Turner wrote:

 For what it's worth, I would like to say that I concur completely with
 Don and Bert.  (Also I would like second Bert's vote of thanks to Don
 for expressing the position so clearly.)

 cheers,

 Rolf Turner

 On 04/02/14 09:56, Bert Gunter wrote:
 Don:

 First, I apologize if this is off topic, but I thought I should reply
 publicly.

 I would only like to say thank you for so eloquently and elegantly
 summarizing my views, also. Maybe that makes me a dinosaur. If so, I
 happily accept the label.

 I find SO's voting for posting business especially irritating. I wish
 merely to post or to read the posts of others without being subjected
 to some kind of online pseudo game and ratings competition. That alone
 keeps me away. But Don said it better.

 I realize that I may be out of step with the masses here, and the
 masses should certainly decide. Hopefully I won't be around if/when
 they decide that R-help should go.

 Best,
 Bert

 Bert Gunter
 Genentech Nonclinical Biostatistics
 (650) 467-7374

 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
 H. Gilbert Welch




 On Mon, Feb 3, 2014 at 12:42 PM, MacQueen, Don macque...@llnl.gov wrote:
 Every 

Re: [R] (no subject)

2014-02-02 Thread Barry Rowlingson
On Sun, Feb 2, 2014 at 6:46 AM, Rolf Turner r.tur...@auckland.ac.nz wrote:
 On 02/02/14 15:37, mohammad javad Azadchehr wrote:
 Hi
 I want R code for bayesian CIF competing risks.
 best regards

 I want wealth, wisdom, good looks, and to play full forward for the
 Sydney Swans.

 One out of four isn't bad.

 To make this useful to the original poster, they should read the
posting guide: http://www.r-project.org/posting-guide.html and
consider how to ask useful questions.

__
R-help@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.


Re: [R] plotting points over a map using R

2014-01-31 Thread Barry Rowlingson
Try reading the R Spatial Task View:

http://cran.r-project.org/web/views/Spatial.html

or this brilliant intro, and other files in that github repository:

https://github.com/Robinlovelace/Creating-maps-in-R/blob/master/intro-spatial.md

or any of the tutorials I've written on the subject!

Barry


On Fri, Jan 31, 2014 at 9:58 AM, 李德磊 dele...@hotmail.com wrote:
 Hello everyone,
 I have no idea how to plotting points over a map using R, in which the colors 
 of the points stand for the points' value. I'd like to get a map as shown in 
 attachment picture which was plotted using matlab. Does anyone know how to do 
 it using R?  Thank you very much for your help in advance.
 Kind regards,Dli

__
R-help@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.


Re: [R] sourcing scripts

2014-01-29 Thread Barry Rowlingson
On Wed, Jan 29, 2014 at 9:26 AM, Ahmed M. El-Kenawy ken...@mans.edu.eg wrote:

 Error in memory.size(min = TRUE) : unused argument (min = TRUE)

 It looks like you've simply typed 'min=TRUE' instead of 'max=TRUE'
somewhere! Somewhere other than the code you sent in the message,
which had max=TRUE. Must be in one of the other scripts sourced in.

Barry

__
R-help@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.


Re: [R] Basic misunderstanding, or problem with my installation?

2014-01-01 Thread Barry Rowlingson
On Wed, Jan 1, 2014 at 4:36 AM, David Parkhurst parkh...@imap.iu.edu wrote:
 Thanks to the three people who saw what I missed.  I typed my
 code in Libre Office as  followed by -, and that program
 converted those two characters into a single left arrow symbol.
 I copied the commands from Libre into R without noticing that
 that had happened.  Wierd.

 You should probably install R Studio and use that! You'll get
syntax highlighting, bracket matching, and no magic conversion of
arrows!

www.rstudio.com

Barry

__
R-help@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.


Re: [R] 3D Surface plot

2013-12-18 Thread Barry Rowlingson
On Wed, Dec 18, 2013 at 2:52 PM, Simon Delay-Fortier
simon.delay-fort...@mail.mcgill.ca wrote:
 Hi everyone,

 I am a very new user of r (doing most of my previous stuff in vba). I am now 
 mandated to draw a 3-d surface of a mine pit hole. I have all the location 
 points (around 5000 points) of the pit in a CSV file under 3 column X, Y  Z. 
 However, going from page to page on the web, I could not figure out how to 
 code the figure. Something I noted is that most of the time X and Y  have to 
 be in ascending order but the data I have are not (since they are finite 
 points of the pit, if X gets  in ascending order, Y and Z are not). Also with 
 the data, sometimes 2 rows fallowing each ohter have the same X and Y value 
 with a different Z. That would be nice if things could be modeled with rgl 
 function in order to have a rotating pit, but I would be glad to only have a 
 3d surface to start!

 How 3d is your surface here? Because there's 3d and there's
what's known as 2.5d

 A 3d surface could be something like the surface of a sphere, or a
cave, or an overhanging cliff, whereas a 2.5d surface is a
single-valued function of x and y.

 If you have a true 3d surface then that's beyond me and involves
working out surface normals and all sorts of other clever stuff which
I don't know about.

 If its really 2.5d then yes, you do need to compute the values of
your surface on a grid in order to display it using rgl's surface3d
function. You can do this with some 2d interpolation code, such as
kriging or inverse distance weighting, using assorted packages such as
automap (which makes it easy but beware) or gstat.

 Since this seems to be a real-world geography problem, you might haul
over to the r-sig-geo mailing list and as there where the spatial guys
hang out.

Barry

__
R-help@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.


Re: [R] read.csv interpreting numbers as factors

2013-12-10 Thread Barry Rowlingson
On Tue, Dec 10, 2013 at 10:06 AM, Jeff Newmiller
jdnew...@dcn.davis.ca.us wrote:
 It is bad netiquette to hijack an existing thread for a new topic. Please 
 start a new email thread when changing topics.

 If your data really consists of what you show, then read.csv won't behave 
 that way. I suggest that you open the file in a text editor and look for odd 
 characters. They may be invisible.

 Going out on a limb, you may be trying to read a tab separated file, and if 
 so then you need to use the sep=”\t argument to read.csv.

Or something in the data isn't a valid number. Try:

as.numeric(as.character(factorthingyouthinkshouldbenumbers))

and if you get any NA values then those things aren't valid number
formats. You need as.numeric(as.character(..)) because otherwise
as.numeric just gets the underlying number codes for the factor
levels.


  f=factor(c(1,1,2,three,4,69))
  f
[1] 1 1 2 three 4 69
Levels: 1 2 4 69 three

  as.numeric(f)
[1] 1 1 2 5 3 4

  as.numeric(as.character(f))
[1]  1  1  2 NA  4 69
Warning message:
NAs introduced by coercion

__
R-help@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.


Re: [R] specify breaks in divergent palette in RColorBrewer: was divergent colors around zero in levelplot()

2013-11-26 Thread Barry Rowlingson
On Tue, Nov 26, 2013 at 1:02 AM, C. Alina Cansler acans...@uw.edu wrote:
 Don,

 This looks helpful:
 https://stat.ethz.ch/pipermail/r-help/2011-March/272361.html

Yes, he's a helpful chap.

 The fundamental problem here is the colour palette. When I was a boy
all we had was a pen plotter with four coloured pens, and of course
you could stick different coloured pens in the different pen slots and
draw four different coloured lines. So your graphics package just said
which number pen it was going to use and the colour that came out was
up to you. Most R graphics functions still have this concept, although
there may be over 100 pens and you don't end up swearing when one runs
out of ink. A numeric value is converted to an integer and the integer
does a lookup in a palette to get the colour.

 What you really want, and what my colourscheme package did, was to
create functions that let users map values directly to colours. You
could then plot points and lines using that function which meant
totally controlled value-to-colour mappings that could be used across
different plots if desired. That worked because points and lines lets
you specify a colour value directly using something like col=#FF23EC
(as well as allowing col=23 and doing a palette lookup).

 But the image function (and probably levelplot) doesn't allow that so
there's various tricks to make functional colour lookups work. I would
convert the image matrix values to a matrix of colours, then create a
matrix of the values 1:(n*m), and then image() that 1:(n*m) matrix
using the colour matrix as a palette. That way each cell had its own
palette entry, and you controlled that colour using the value-colour
function.

 Or you could just use ggplot which I'm pretty sure has the same
concept of mapping values to colours.

Barry

__
R-help@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.


Re: [R] specify breaks in divergent palette in RColorBrewer: was divergent colors around zero in levelplot()

2013-11-26 Thread Barry Rowlingson
On Tue, Nov 26, 2013 at 9:58 AM, Prof Brian Ripley
rip...@stats.ox.ac.uk wrote:

   But the image function (and probably levelplot) doesn't allow that so

 Mis-information alert!   The help says

   col: a list of colors such as that generated by ‘rainbow’,
‘heat.colors’, ‘topo.colors’, ‘terrain.colors’ or similar
functions.

 and look at what they generate.  Or see e.g. ?col2rgb .

 Although base graphics has the concept of a palette of colours, AFAIK it
 has always been bolted on top of a general colour specification,
 originally RGB and for many years already RGBA.


 Yes image allows you to specify col=, but it always specifies a
palette. The matrix values are scaled from 1:length(col) and looked up
in that palette. You can't call image with z as matrix of colours and
get those colours, nor set col to a matrix of colours and a see those
colours laid out. This is unlike points() where specifying col= as a
vector of the same length as the number of points gives you a 1:1
mapping of points to colours.

 To do image() with a 1:1 mapping of cell values to colours requires a
tiny bit of hoop-jumping.

Barry

__
R-help@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.


Re: [R] Should there be an R-beginners list?

2013-11-25 Thread Barry Rowlingson
If you want a vision of an R-beginners list, it is a boot stamping
ITS IN THE DOCUMENTATION into a newbies face - forever.

http://www.brainyquote.com/quotes/quotes/g/georgeorwe159438.html

slight exaggeration perhaps, but most R-beginners would benefit from
reading a bit more documentation and LURKING MOAR on the mailing
list before asking. Same applies to posting on StackOverflow.

Barry


On Mon, Nov 25, 2013 at 12:08 PM, Arman Eshaghi arman.esha...@gmail.com wrote:
 I do not agree with a separate beginner's list. But I do stand with moving
 to stackoverflow, mainly because of the easier google search than current
 mailing list. It could make it more accessible.


 On Mon, Nov 25, 2013 at 4:07 AM, John Sorkin 
 jsor...@grecc.umaryland.eduwrote:

 Mailing list vs. stack overflow, I have no opinion, but
 beginners list NO! I was a beginner at one time and the
 mailing list worked just fine. I see no reason to divide our
 efforts across two lists (be they mailing lists or stack overflow).
 John


 John David Sorkin M.D., Ph.D.
 Professor of Medicine
 Chief, Biostatistics and Informatics
 University of Maryland School of Medicine Division of Gerontology and
 Geriatric Medicine
 Baltimore VA Medical Center
 10 North Greene Street
 GRECC (BT/18/GR)
 Baltimore, MD 21201-1524
 (Phone) 410-605-7119
 (Fax) 410-605-7913 (Please call phone number above prior to faxing)
  memilanuk memila...@gmail.com 11/24/2013 7:30 PM 
 On 11/24/2013 12:04 PM, Rich Shepard wrote:
  On Sun, 24 Nov 2013, Yihui Xie wrote:
 
  Mailing lists are good for a smaller group of people, and especially
  good when more focused on discussions on development (including bug
  reports). The better place for questions is a web forum.
 
 I disagree. Mail lists push messages to subscribers while web fora
  require
  one to use a browser, log in, then pull messages. Not nearly as
 convenient.
 
  Rich
 

 With the StackOverflow model, you can either view the list of posts
 related to a specific tag via RSS, or subscribe for email notification
 of new updates on that topic.

 Add in the added bonus of the ability to moderate and/or cull spam and
 redundant questions, etc. and the targeted focus of a SO-type forum
 increases dramatically IMHO.

 __
 R-help@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.


 Confidentiality Statement:
 This email message, including any attachments, is for ...{{dropped:18}}

 __
 R-help@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.

__
R-help@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.


Re: [R] Should there be an R-beginners list?

2013-11-25 Thread Barry Rowlingson
Joran (on StackOverflow chat, funnily enough) has just pointed us to this:

http://www.win.tue.nl/~bvasiles/papers/cscw14.pdf  How Social QA
Sites are Changing Knowledge Sharing
in Open Source Software Communities

which includes a graph of postings to R-help and questions tagged
'[r]' on StackOverflow. By the end of 2012 SO was getting about twice
as many [r]-tagged questions as R-help was getting new threads.

The paper is a very detailed discussion on the use of mailing lists
and discussion sites.


On Mon, Nov 25, 2013 at 3:25 PM, Marc Schwartz marc_schwa...@me.com wrote:
 On Nov 25, 2013, at 7:56 AM, PIKAL Petr petr.pi...@precheza.cz wrote:

 Hi

 I doubt if people start to search answers if they often do not search them
 in help pages and documentation provided.

 I must agree with Duncan that if Stackoverflow was far more better than
 this help list most people would seek advice there then here. Is there any
 evidence in decreasing traffic here?

 Anyway, similar discussion went in 2003 with outcome that was not in
 favour for separate beginner list
 http://tolstoy.newcastle.edu.au/R/help/03b/7944.html

 Petr

 BTW it is pitty that r help archive does not extend over year 2012. I
 found that *Last message date: Tue 31 Jan 2012 - 12:19:21 GMT


 Petr,

 I may be confusing your final statement above, but the **main** R-Help
 archive is current to today:

   https://stat.ethz.ch/pipermail/r-help/

 That being said, as one who has been interacting on R-Help (and other R-*
 lists) for a dozen years or so, I would have to say that one would need to
 have their head in the sand to not be cognizant of the dramatic decline in
 the traffic on R-Help in recent years. Simply keeping subjective track of
 the declining daily traffic ought to be sufficient.

 Due to work related time constraints, my posting here in recent times has
 dropped notably. I do still read many of the R-Help posts and along with
 Martin, am co-moderator on R-Devel. So am still involved in that capacity.

 I do follow SO and SE via RSS feed, so am aware of the increasing traffic
 there, albeit, I have not posted there.

 In addition, there are a multitude of other online locations where R related
 posts have begun to accumulate. These include various LinkedIn groups, R
 related blogs, ResearchGate and others. I do believe, however, that SO is
 the dominant force in the shift of traffic.

 To answer Petr's question above, I updated and re-ran some code that I had
 used some years ago to estimate the traffic on various lists/fora:

   https://stat.ethz.ch/pipermail/r-help/2009-January/184196.html

 To that end, I am attaching a PDF file that contains a barplot of the annual
 R-Help traffic volume since 1997, through this month. The grey bars
 represent the actual annual traffic volumes of posts to R-Help.

 For 2013, I added a red segment to the bar, which shows the projected number
 of posts for the full year, albeit, it is simply based upon the mean number
 of posts per day, averaged over the YTD volume, projected over the remaining
 days in the year, without any seasonal adjustments. So it may be optimistic,
 as we are coming into the holiday season for many.

 Bottom line, while the trend was dramatically positive through 2010, peaking
 at a little over 41,000 total posts, the volume has just as dramatically
 declined in 2013 to a projected ~21,400. This means that the volume for 2013
 has dropped back to the approximate volume of 2005.

 Only time will tell if the dramatic decline will continue, or reach some new
 reasonable asymptote that is simply reflective of the distribution of
 traffic on various other online resources.

 To the original query posted by Bert, I would say no, there is not a need
 for a beginner's list.

 Regards,

 Marc Schwartz





 __
 R-help@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.

__
R-help@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.


Re: [R] quotation marks and scan

2013-11-17 Thread Barry Rowlingson
On Sun, Nov 17, 2013 at 10:42 PM, R. Michael Weylandt
michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:
 They're not actually there so don't try too hard to rid yourself of them:

 x - \'

 length(x)
 print(x)
 cat(x, \n)

 Did you mean to do 'nchar(x)' to show that \ was one character?
'length' gives the number of elements in a vector, which in this case
is also one.

  x=c(\, '\'')
  length(x)
 [1] 2
  nchar(x)
 [1] 1 1

__
R-help@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.


Re: [R] how to derive true surface area from `computeContour3d' (misc3d package) -- follow up

2013-11-08 Thread Barry Rowlingson
On Fri, Nov 8, 2013 at 1:01 PM, j. van den hoff
veedeeh...@googlemail.com wrote:


 ps: it of course would still be nice, if the surface area (or a vector
 containing the individual triangle areas)
 were returned to the caller as well ...

 Does the 'surfaceArea' function in the sp package do what you want?
It's Edzer's integration of an R function that I wrote that calls some
C code that someone else wrote that implements an algorithm from 2004.

 You just need to coerce your grid data into the right form.

 Barry

__
R-help@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.


Re: [R] ascii-grid export

2013-11-06 Thread Barry Rowlingson
On Mon, Nov 4, 2013 at 7:27 AM, Enzo Cocca enzo@gmail.com wrote:
 yes barry I really need this.

 I tried to use raster or rgdal but with poor results.

 I have this function:

 VGM_PARAM_A3 - gstat(id=bos_bison,
 formula=combusto~1,locations=~coord_x+coord_y, data=archezoology_table,
 nmax = 10)

 VGM_PARAM_A3 - gstat(VGM_PARAM_A3, model=vgm(1, Sph, 5, 0),
 fill.all=TRUE)

 ESV_A3 - variogram(VGM_PARAM_A3, map=True, with=0.1, cutoff=9)

 VARMODEL_A3 = fit.lmc(ESV_A3, VGM_PARAM_A3)

 plot(ESV_A3, threshold = 5, col.regions = bpy.colors(), xlab=, ylab=,
 main=Map - A3)
 png(C:\Users\User\pyarchinit_R_folder\A3 semivariogram_map.png,
 width=1, height=1, res=400)

 I make a png file but how can I convert it in ascii-grid?

Why do you want to make an ascii-grid out of this? The variogram map
isn't in geographical coordinates, its in coordinate differences in x
and y

The return value when map=TRUE doesn't seem to be too well documented,
but looks like it is a list with a 'map' element that is a spatial
pixels data frame. Here's an example using the demo data (I can't run
your code because I don't have your data, please try and make your
problems easily reproducible):

require(sp)
require(gstat)
data(meuse)
coordinates(meuse)=~x+y
v=variogram(log(zinc)~1, meuse,map=TRUE,cutoff=900,width=10)
class(v$map)
[1] SpatialPixelsDataFrame
attr(,package)
[1] sp

Now that can be written using rgdal's writeGDAL function.

However, you need the AAIGrid driver to work properly:

 writeGDAL(v$map,vmap.ag,driver=AAIGrid)
Error in .local(.Object, ...) : Dataset copy failed

raster package to the rescue:

 require(raster)
 writeRaster(raster(v$map),v.asc,ascii)
class   : RasterLayer

[etc]

When I look at the file, I have an ESRI grid file:

$ head -5 v.asc
NCOLS 181
NROWS 181
XLLCORNER -905
YLLCORNER -905
CELLSIZE 10
[+ data]

Now, that's assuming you wanted to write the data, not a pretty image
picture like you get when you plot the variogram map. And there's
still the mystery of why you want to write a non-geographic
coordinate-based dataset to a geographic data format...

 And you should probably have asked this on R-sig-geo where the
geographRs (including the authors of gstat) hang out.

 Hope this helps anyway.

Barry

__
R-help@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.


Re: [R] convert one digit numbers to two digits one

2013-11-06 Thread Barry Rowlingson
All these suggestions of using 'sprintf' might be right but you might
be doing it wrong...

If you are working with times, then use the date/time classes and the
handy functions for working on them. Which means the lubridate
package, most likely.

Are these times part of a calendar time, or are they just clock times
without reference to any day, or are they durations in hours and
minutes?



On Wed, Nov 6, 2013 at 4:34 PM, Marc Schwartz marc_schwa...@me.com wrote:
 On Nov 6, 2013, at 10:25 AM, Alaios ala...@yahoo.com wrote:

 Hi all,
 the following returns the hour and the minutes

 paste(DataSet$TimeStamps[selectedInterval$start,4], 
 DataSet$TimeStamps[selectedInterval$start,5],sep=:)
 [1] 12:3

 the problem is that from these two I want to create a time stamp so 12:03. 
 The problem is that the number 3 is not converted to 03. Is there an easy 
 way when I have one digit integer to add a zero in the front? Two digits 
 integers are working fine so far, 12:19, or 12:45 would appear correctly

 I would like to thank you in advance for your help

 Regards
 Alex


 This is an example where using ?sprintf gives you more control:

 sprintf(%02d:%02d, 12, 3)
 [1] 12:03

 sprintf(%02d:%02d, 9, 3)
 [1] 09:03


 The syntax '%02d' tells sprintf to print the integer and pad with leading 
 zeroes to two characters where needed.

 Regards,

 Marc Schwartz

 __
 R-help@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.

__
R-help@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.


Re: [R] Basic question: why does a scatter plot of a variable against itself works like this?

2013-11-06 Thread Barry Rowlingson
Interestingly, fitting an LM with x on both sides gives a warning, and
then drops it from the RHS, leaving you with just an intercept:

 lm(x~x,data=d)

Call:
lm(formula = x ~ x, data = d)

Coefficients:
(Intercept)
  4

Warning messages:
1: In model.matrix.default(mt, mf, contrasts) :
  the response appeared on the right-hand side and was dropped
2: In model.matrix.default(mt, mf, contrasts) :
  problem with term 1 in model.matrix: no columns are assigned

there's no numerical problem fitting a line through the points:

  d$xx=d$x
  lm(x~xx,data=d)

Call:
lm(formula = x ~ xx, data = d)

Coefficients:
(Intercept)   xx
  5.128e-161.000e+00

It seems to be R saying Ummm did you really mean to do this? It's kinda dumb.

I suppose this could occur if you had a nested loop over all columns
in a data frame, fitting an LM with every column, and didn't skip if
i==j

Except of course it doesn't:

 - fit with two indexes set to one:

 i=1;j=1
 lm(d[,i]~d[,j])

Call:
lm(formula = d[, i] ~ d[, j])

Coefficients:
(Intercept)   d[, j]
  5.128e-161.000e+00

- fit with two ones:

 lm(d[,1]~d[,1])

Call:
lm(formula = d[, 1] ~ d[, 1])

Coefficients:
(Intercept)
  4

Warning messages:
1: In model.matrix.default(mt, mf, contrasts) :
  the response appeared on the right-hand side and was dropped
2: In model.matrix.default(mt, mf, contrasts) :
  problem with term 1 in model.matrix: no columns are assigned

Obviously this can all be explained in terms of R (or lm's, or
model.matrix's) evaluation schemes, but it seems far from intuitive.

Barry



On Wed, Nov 6, 2013 at 4:59 PM, William Dunlap wdun...@tibco.com wrote:
 It probably happens because plot(formula) makes one call to terms(formula) to
 analyze the formula.  terms() says there is one variable in the formula,
 the response, so plot(x~x) is the same a plot(seq_along(x), x).
 If you give it plot(~x) , terms() also says there is one variable, but
 no response, so you get the same plot as plot(x, rep(1,length(x))).
 This is also the reason that plot(y1+y2 ~ x1+x2) makes one plot of the sum of 
 y1 and y2
 for each term on the right side instead of 4 plots, plot(x1,y1), 
 plot(x1,y2),plot(x2,y1),
 and plot(x2,y2).

 One could write a plot function that called terms separately on the left and
 right sides of the formula.

 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Tal Galili
 Sent: Wednesday, November 06, 2013 8:40 AM
 To: r-help@r-project.org
 Subject: [R] Basic question: why does a scatter plot of a variable against 
 itself works like
 this?

 Hello all,

 I just noticed the following behavior of plot:
 x - c(1,2,9)
 plot(x ~ x) # this is just like doing:
 plot(x)
 # when maybe we would like it to give this:
 plot(x ~ c(x))
 # the same as:
 plot(x ~ I(x))

 I was wondering if there is some reason for this behavior.


 Thanks,
 Tal



 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 --

   [[alternative HTML version deleted]]

 __
 R-help@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.

 __
 R-help@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.

__
R-help@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.


Re: [R] Questions about R

2013-11-06 Thread Barry Rowlingson
On Wed, Nov 6, 2013 at 5:44 PM, Ye Lin ye...@lbl.gov wrote:
 You can get details at http://www.r-project.org/

 But to answer your question: Yes it is free

 But there is also a paid version. Send me $1000 and I will send you R
on a USB stick, complete with all the source code.

 Seriously, other companies do supply support and extensions for R at
a cost, and although I can legally sell you a copy of R for $1000
nobody bothers charging for R because the license can't stop you
giving your copy away.

 As for your security/data safety question, well your operating system
is probably the weaker link in that chain. However if you are running
R in a client-server fashion then you should make sure the data is
encrypted - and then the weakest link is possession of the private
half of the encryption key, which is your responsibility.

Barry

__
R-help@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.


Re: [R] Download CSV Files from EUROSTAT Website

2013-11-05 Thread Barry Rowlingson
On 4 Nov 2013 19:30, David Winsemius dwinsem...@comcast.net wrote:

 Maybe you should use their download facility rather than trying to
deparse a complex webpage with lots of special user interaction features:

 http://appsso.eurostat.ec.europa.eu/nui/setupDownloads.do


That web page depends on the user already having been to the previous page
to set up a session and so directly downloading a dataset requires setting
up cookies and making sure the request has all the right parameters. Looks
like a right pain.

--
 David.
 

 On Nov 4, 2013, at 11:03 AM, Lorenzo Isella wrote:

  Thanks.
  I had already introduced this minor adjustments in the code, but the
real problem (to me) is the information that gets lost: the informative
name of the columns, the indicator type and the units.

  Cheers
 
  Lorenzo
 
  On Mon, 04 Nov 2013 19:52:51 +0100, Rui Barradas ruipbarra...@sapo.pt
wrote:
 
  Hello,
 
  If you want to get rid of the (bp) stuff, you can use lapply/gsub.
Using Jean's code a bit changed,
 
  library(XML)
 
  mylines - readLines(url(http://bit.ly/1coCohq;))
  closeAllConnections()
  mytable - readHTMLTable(mylines, which = 2, asText=TRUE,
stringsAsFactors = FALSE)
 
  str(mytable)
 
  mytable[] - lapply(mytable, function(x) gsub(\\(.*\\), , x))
  mytable[] - lapply(mytable, function(x) gsub(,, , x))
  mytable[] - lapply(mytable, as.numeric)
 
  colnames(mytable) - 2000:2013
 
 
  Hope this helps,
 
  Rui Barradas
 
  Em 04-11-2013 09:53, Lorenzo Isella escreveu:
  Hello,
  And thanks a lot.
  This is indeed very close to what I need.
  I am trying to figure out how not to lose the headers and how to
avoid
  downloading labels like (p) together with the numerical data I am
  interested in.
  If anyone on the list knows how to make this minor modifications, s/he
  will make my life much easier.
  Cheers
 
  Lorenzo
 
 
  On Fri, 01 Nov 2013 14:25:49 +0100, Adams, Jean jvad...@usgs.gov
wrote:
 
  Lorenzo,
 
  I may be able to help you get started.  You can use the XML package
to
  grab the information off the internet.
 
  library(XML)
 
  mylines - readLines(url(http://bit.ly/1coCohq;))
  closeAllConnections()mylist - readHTMLTable(mylines,
  asText=TRUE)mytable - mylist1$xTable
 
  However, when I look at the resulting object, mytable, it doesn't
have
  informative row or column headings.  Perhaps someone else can figure
  out how to get that information.
 
  Jean
 
 
 
 
 
  On Thu, Oct 31, 2013 at 10:38 AM, Lorenzo Isella
  lorenzo.ise...@gmail.com wrote:
  Dear All,
  I often need to do some work on some data which is publicly
available
  on the EUROSTAT website.
  I saw several ways to download automatically mainly the bulk data
  from EUROSTAT to later on postprocess it with R, for instance
 
  http://bit.ly/HrDICj
  http://bit.ly/HrDL10
  http://bit.ly/HrDTgT
 
  However, what I would like to do is to be able to download directly
  the csv file corresponding to a properly formatted dataset
  (typically a dynamic dataset) from EUROSTAT.
  To fix the ideas, please consider the dataset at the following link
 
  http://bit.ly/1coCohq
 
  what I would like to do is to automatically read its content into R,
  or at least to automatically download it as a csv file (full
  extraction, single file, no flags and footnotes) which I can then
  manipulate easily.
  Any suggestion is appreciated.
  Cheers
 
  Lorenzo
 
  __
  R-help@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.
  __
  R-help@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.
 
  __
  R-help@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.

 David Winsemius
 Alameda, CA, USA

 __
 R-help@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.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] ascii-grid export

2013-11-02 Thread Barry Rowlingson
Or do you mean you want to write the gridded output of an
interpolation you did (perhaps using kriging) in gstat as an ESRI
ASCII Grid file for reading into a GIS?

If so, you can probably do it with writeGDAL from the rgdal package,
or writeRaster from the raster package.

I don't really know what a 'semivariogram map' is.


On Sat, Nov 2, 2013 at 8:55 AM, Enzo Cocca enzo@gmail.com wrote:
 hi,

 I want to export in ascii-grid file a semivariogram map that I have did
 with gstat library.

 How can I make it?

 Somebody can help me?
  thanks!

 enzo
 --
 Enzo Cocca (PhD Candidate)
 Research Fellow
 Università di Napoli L'Orientale
 mail: enzo@gmail.com
 cell: +393495087014

 [[alternative HTML version deleted]]


__
R-help@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.


Re: [R] Code Book from SPSS Data

2013-10-27 Thread Barry Rowlingson
On Sat, Oct 26, 2013 at 9:37 PM, Peter Maclean pmaclean2...@yahoo.com wrote:
 I do not have SPSS and I would like to create a code book in a data frame 
 format using R.

 #How could I extract a codebook (without Summary statistics for printing)?

 This isn't that clear because I don't think 'codebook' is something
well-defined. Describe the rows and columns of the data frame you want
to create.

Barry

__
R-help@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.


Re: [R] May I send a zip attachment to a post?

2013-10-22 Thread Barry Rowlingson
On Mon, Oct 21, 2013 at 10:51 PM, David Winsemius
dwinsem...@comcast.net wrote:

 On Oct 21, 2013, at 2:15 PM, Hurr wrote:

 May I send a .zip file attached to a post?

 No.

 That's not explicit from the posting guide:

No binary attachments except for PS, PDF, and some image and archive formats 

 you have to click through to the General Instructions to see:

Furthermore, most binary e-mail attachments are not accepted, i.e.,
they are removed from the posting completely. As an exception, we
allow application/pdf, application/postscript, and image/png (and
x-tar and gzip on R-devel).

Maybe the posting guide should be more explicit - not that anyone reads it...

Barry

__
R-help@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.


Re: [R] What is the difference between Reduce(…) and do.call(…) ?

2013-10-08 Thread Barry Rowlingson
On Tue, Oct 8, 2013 at 10:22 AM, Asis Hallab asis.hal...@gmail.com wrote:
 Dear R-Experts,

 So, what is the difference between Reduce and do.call and when best to
 use which?

From the help:

‘Reduce’ uses a binary function to successively combine the
 elements of a given vector and a possibly given initial value.

  ‘do.call’ constructs and executes a function call from a name or a
 function and a list of arguments to be passed to it.


 In your example, rbind gets called N-1 times when using Reduce (where
N is the length of the list) because it is doing something like:

 rbind(x[[1]],rbind(x[[2]],x[[3]]))

For longer lists, its doing something like (where a b c d e are list
elements x[[1]] to x[[5]])

rbind( a, rbind( b, rbind( c, rbind( d, e ) ) ) )

whereas do.call calls it once, as rbind(a,b,c,d,e)

Use Reduce when you are doing a Reduce operation (read up on
Functional Programming). Use do.call when you want to call a function
with parameters in a list.

Barry

__
R-help@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.


Re: [R] Importing odf file into R

2013-10-04 Thread Barry Rowlingson
On Fri, Oct 4, 2013 at 5:57 AM, Peter Maclean pmaclean2...@yahoo.com wrote:
 Anyone aware of a package or technique to import odf data file into R, I will 
 appreciate his/her help.

A quick scan of R-help points me here:

http://www.omegahat.org/ROpenOffice/

Reports of that working (or not) would be appreciated - I've not tried it.

Alternatively, there's python code for reading ODF so you could
interface to that in a number of ways.

Barry

__
R-help@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.


Re: [R] Understanding classes in R

2013-09-30 Thread Barry Rowlingson
On Sun, Sep 29, 2013 at 10:48 PM, john doe anon.r.u...@gmail.com wrote:
 I am having trouble understanding how classes in R work.  Here is a small
 reproducable example:

 x=1
 class(x)
 [1] numeric

 OK.  When a variable is a number, its class is numeric.  Does R have
 multiple types for numbers, like C++ (eg integer, float, double).  If so,
 where can I see a list, and how does numeric fit into this system?

 x=1:100
 class(x)
 [1] integer

 Wait - I thought that I assigned x to be an array/vector of 100 integers
 (numerics).  Why is the class not array or vector.  How is integer
 different than numeric?  Is there a vector or array class in R?  If
 so, why is this not that?

In most programming languages scalars and vectors (aka 1-d arrays) are
completely different things. However in R a scalar is the same thing
as a length-1 vector. Don't think of x=1 and x=1:100 as the first
creating a scalar and the second creating a vector containing 100
scalar values. The first creates a vector containing 1 scalar value,
and the second creates a vector conatining 100 scalar values. You
can't really get scalar values, they'll always effectively be in a
vector of length 1.

So the return value of class here is actually short for 'vector of
numeric' or 'vector of integer' - even when the length is 1 - and you
can think of those as the basic numeric classes. There is no 'scalar
numeric' class, all is vectors. is.vector(1) is TRUE. There isn't even
an is.scalar function.

None of that is true for 2-d arrays, aka matrices, where class(m) is
always matrix whether its a matrix of characters or numbers. You
have to look at the mode(m) or typeof(m) (or storage.mode(m)) to
figure out what kind of thing a matrix 'm' contains.

A 'list' is a bit more like some of the generic container classes that
you find in other programming langages. Its elements can be anything
but its class is always 'list'. Use it when you want a vector (in the
general sense of 'vector') of non-scalar values, eg L =
list(c(1,2,3),1,c(99,120),c(foo,bar,baz))

Confused? Well, just forget everything you learned about classes in
your Comp Sci lessons and get ready to learn R's two incompatible
OO-programming systems (S3 and S4 classes), or four if you want to
look at even more OO systems people have implemented as add-on
packages

Barry

__
R-help@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.


Re: [R] Combining rasters

2013-09-06 Thread Barry Rowlingson
[Probably an R-Sig-geo question...]



On Fri, Sep 6, 2013 at 3:57 PM, philippe massicotte
pmassico...@hotmail.com wrote:
 Hi everyone.

 I would like to know if it is possible to combine rasters in R to form a 
 collage.

 For example, I would like to place 2 copies of the R logo side by side.


 r = raster(system.file(external/rlogo.grd, package = raster))

 Convert to matrix, cbind, convert to raster:

  r2 = raster(cbind(as.matrix(r),as.matrix(r)))
  plot(r2)

If you want to preserve the x and y scale somehow then you need to
think about exactly where you are putting the second r and set xmx,
ymx xmn, ymn when you construct the new raster.

Barry

__
R-help@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.


Re: [R] GO TO function in R

2013-08-02 Thread Barry Rowlingson
No. We figured this out in 1968.
http://dl.acm.org/citation.cfm?doid=362929.362947


On Fri, Aug 2, 2013 at 3:20 AM, David Winsemius dwinsem...@comcast.net wrote:

 On Aug 1, 2013, at 6:58 PM, Peter Maclean wrote:

 Does R has a GO TO function? For example, I want to run this script at a 
 given interval and save the results.


 Generally communication is more effective if you make your goals clear in a 
 natural language (English in the case of this mailing list) first.

 #Step one
 a - Sys.time()
 b - paste(Figure_, a, sep =  )
 shape - as.numeric(a)/1
 scale - as.numeric(a)/100
 #I want to save the file using b object (above) as a file name
 #However it is saved as b.pdf
 pdf(f:/b.pdf) #How to save the file using b above?

 Perhaps:

 pdf(file=paste0(f:/, b, .pdf))

 par(mfrow=c(2,1))
 x - sort(rgamma(100, shape=shape, scale = scale))
 y - dgamma(x, shape=shape, scale = scale)
 par(mfrow=c(2,1))
 plot(x, y, type=l,col=red, lwd=5)

 #Step 2
 Sys.sleep(2) # For Quick results in the model it is one hour
 shape - (as.numeric(Sys.time()))/1
 scale - (as.numeric(Sys.time()))/100
 x - sort(rgamma(100, shape=shape, scale = scale))
 y - dgamma(x, shape=shape, scale = scale)
 plot(x, y, type=b,col= dark red, lwd=5)
 dev.off()
 #Step 3
 Sys.sleep(2)  #Again in the model it is one hour

 #  it?  It would help if you explained what it is.

 #I Want to go back to step 1 to start over again


 I think is a measure of my success in training my mind to think functionally 
 that I cannot conceive of how I would use GOTO as a function.

 (Using `replicate`, I can imagine.)

 --
 David.

 Sincerely,

 Peter Maclean
 Department of Economics
 UDSM
   [[alternative HTML version deleted]]

 __
 R-help@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.

 David Winsemius
 Alameda, CA, USA

 __
 R-help@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.

__
R-help@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.


Re: [R] Plotting gps coordinates on Shapefile

2013-06-13 Thread Barry Rowlingson
On Thu, Jun 13, 2013 at 6:26 AM, L S losedag...@gmail.com wrote:

 I realized that the coordinates are completely different.  The coordinates
 in my data file (i.e. my csv file) are traditional GPS coordinates (e.g. 39.17
 or 76.37).  The shapefile however has x,y values such as 1416813.54262877
 or 561125.546602725. I am not familiar with what type of coordinate system
 those values use.

 How can I change the coordinates in my csv file to match the same system as
 my shapefile or the other way around--i.e. to get my shapefile to have
 similar coordinates as my csv file?

 You really need to know the coordinate reference system that your
points are in.

 What you call traditional GPS coordinates is formally known as
EPSG:4326. I suspect your points are in some small-region plane
coordinate system. In the UK, for example, we have a square metric
grid system that is EPSG:27700. The units of this system are metres
from a point origin off the south-west of the UK, which is great for
small areas in the UK but not applicable to India, because it assumes
a flat earth. If your data is in the USA, then it might be one of the
state plane systems. There and elsewhere, it might be one of the
global UTM zones (but you have to know which one).

There are thousands of possible coordinate systems:
http://www.epsg-registry.org/ or you can make your own using PROJ4
strings...

 To convert from one coordinate system to another, I normally use
spTransform from the rgdal package since I mostly work with sp-class
objects. I think there's a 'project' function that can work with raw
x-y coordinates in vectors or matrices.

 You can also try asking on the R-sig-geo mailing list where the map
people hang out.

Barry

__
R-help@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.


Re: [R] Loading an .RData file and assigning the loaded objects within a loop

2013-06-01 Thread Barry Rowlingson
Within lapply load the file and return the value of the thing or
things in the file you want. Something like this:

  files
[1] x1.RData x2.RData x3.RData x4.RData

  lapply(files,function(z){load(z);x})
[[1]]
[1] 1

[[2]]
[1] 22

[[3]]
[1] 333

[[4]]
[1] 

Each of my files contains a single number stored in an object called
'x'. Within the loop 'x' has the value just loaded from the file.

Another method is to use the environment argument of load to save into
an environment other than the global one...




On Sat, Jun 1, 2013 at 11:52 AM, Jim Holtman jholt...@gmail.com wrote:
 use 'lapply' to read in the .RData file.  Therefore each file is stored as an 
 element of a list thatb
  you can access and change as necessary.

 Sent from my iPad

 On Jun 1, 2013, at 6:18, Jeremy Ng jeremy.ng.wk1...@gmail.com wrote:

 Hi all,

 I tried to look this up online, but am still feeling a little stuck.

 I have a bunch of Rdata files in side my directory, and I would like to
 load all of them in a loop. Each time the next is read in, it would
 over-write the previously read in object because they will be assigned the
 same workspace object name.

 Is there anyway for each individually read in Rdata object to be assigned a
 new name?

 Thanks!
 JEremy

[[alternative HTML version deleted]]

 __
 R-help@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.

 __
 R-help@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.

__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Barry Rowlingson
On Tue, May 28, 2013 at 7:54 AM, Mark Breman breman.m...@gmail.com wrote:
 Hello List,

 When i paste a large block of R code from an editor to the R command line
 the execution of the code will often fail at some point because it is not
 pasted as it was copied.

 This reminds me of the Tommy Cooper joke (I can't do the voice,
especially over email):

Man: Doctor, it hurts when I do this [waves arm about]
Doc: Well don't do that then.

 Cutting and pasting code - especially large blocks of code - is a
poor way to work with R. Make your code re-usable by putting it in
functions with sensible arguments and meaningful return values. Debug
your functions with little test data sets, or go the whole hog and use
package:testthat for writing test suites. Organise your functions into
packages and use package:devtools to make packages REALLY REALLY easy.
 Easier than having a big text file with all the R code you've ever
written in, and then pasting chunks of into R every time. Or pasting
it back into your big text file and then changing a little bit of it
so you now have two very similar chunks of R code with the same bug
now in two positions

 Take a day to read up on how to effectively work with R with
functions and packages, then revisit your work and see how that can
apply to you. You'll get that day back within a couple of weeks.

B

__
R-help@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.


Re: [R] Help retrieving only Portuguese words from a file

2013-05-28 Thread Barry Rowlingson
On Tue, May 28, 2013 at 5:02 PM, Rui Barradas ruipbarra...@sapo.pt wrote:
 Hello,

 And some words exist in Portuguese, Spanish and English, the three
 languages of the problem. For instance, animal. I don't think this
 problem can be solved, but a dictionary search would tell if it is a
 Portuguese word, which it is.

 Is there any structure to the text? If it has complete paragraphs in
one of the three languages then you can probably make a better guess
of the language of the paragraph from the presence of key words. I
wonder if some of the code for detecting spam can help you here...
Train it on some known Portuguese, Spanish, and English text...

 If its just a stream of words in one of the languages in a random
order then it is difficult or impossible.

Barry

__
R-help@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.


Re: [R] spatially analyzing multiple data layers

2013-05-25 Thread Barry Rowlingson
On Sat, May 25, 2013 at 7:09 PM, Amy Henry amybethhe...@gmail.com wrote:
 Hi, I started using R about 3 months ago so please excuse my ignorance. I
 have two datasets. The first consists of 247 fixed position mosquito traps
 that were serviced weekly for 23 weeks. The second is dengue incidence data
 indexed to home address for the same time period. I would like to see if
 there is a space time relationship between mosquito catch rate and dengue
 incidence. So far I have been unable to locate a package for multilayer
 spatial analysis or a space-time analysis that would answer the question.
 Does anyone have advise on where I should look?

 Do you have a statistical model in mind? Something like your mosquito
count data is noisy samples from an underlying spatio-temporally
smooth rate (with some space-time covariance structure), and that your
dengue incidence is dependent on that (in some way, perhaps you need
cases and controls for a logistic regression). Looks like a
spatio-temporal errors-in-variables model. Is it? Maybe you can take a
point pattern approach with the cases as an inhomogeneous space-time
poisson process with intensity given by the smoothed mosuito
measurement data... You need to figure out the stats before you go off
fishing for a package. Or are you expecting to be able to plug in your
data, crank a handle, and get an answer out?

 Have you explored the data at all? You could try some simple time
series exploratory plots (maybe there's a monthly pattern caused by
the moon?) or a few maps of the totals over all time.

 Ideally you should figure out the stats before you even collect the data...

Barry

__
R-help@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.


Re: [R] Transform Coordinate System of an ASCII-Grid

2013-05-23 Thread Barry Rowlingson
On Thu, May 23, 2013 at 8:44 AM, jas
jacqueline.schwei...@wuestundpartner.com wrote:
 Dear all,


 I have an ASCII-Grid for Switzerland in the Swiss National Coordinate System
 of CH1903. Now for a Webapplication of the ASCII-Grid, I need to deliver the
 ASCII-Grid in the WGS84 System.

 Via coordinates(ascii) I can export the coordinates and convert them with
 a formula into WGS84. My problem is now, how can I implement these into the
 ASCII-Grid, so that the whole grid-structure is from now on gonna be saved
 in the WGS84-coordinate format?
 (important: I don't want to change the projection, I want to actually change
 the numeric format of the coordinates)

You can't change the numeric format of the coordinates without
changing the projection (unless changing from km to m).

In your original coordinate system your grid is a bunch of rectangles
with straight sides and right angles. In your WGS84 system the squares
are no longer square, the sides are no longer straight, and the angles
are no longer 90 degrees. This is all too complicated for a simple
grid data structure to comprehend.

 The solution may be to reproject your grid. This is a transformation
of values, much like stretching an image file, from one grid to
another. raster:projectRaster can do this for you.

For a dataset with a small extent, for some small values of small,
you may be able to get away with transforming the corner coordinates
and ignoring the fact that the earth is not flat. But this will make
everyone who thinks the earth is round cry.

 You should also look into the raster package for more info. You've
not said what you're using to read the data.

 You should probably ask in r-sig-geo anyway, where the mappers hang out.

Barry

__
R-help@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.


Re: [R] peering inside functions in a package?

2013-05-17 Thread Barry Rowlingson
On Fri, May 17, 2013 at 2:56 AM, Seth Myers sjmyers3...@gmail.com wrote:

 Let's say I would like to look inside the function corBrownian in library
 (ape).  When I type in the function name I get the following, which is not
 nearly the detail that goes into this function.  I am wondering how to
 begin cracking this function open (and others) so I can learn more about it
 and perhaps code my own corClass one day.  Thanks.

  corBrownian
 function (value = 1, phy, form = ~1)
 {
 if (!inherits(phy, phylo))
 stop(object \phy\ is not of class \phylo\)
 attr(value, formula) - form
 attr(value, fixed) - TRUE
 attr(value, tree) - phy
 class(value) - c(corBrownian, corPhyl, corStruct)
 value
 }
 environment: namespace:ape


Your premise is wrong! This is exactly all that goes into the corBrownian
function. All that it does is create a thing with some values and most
importantly, a set of class attributes.

 It's via that class attribute that your corBrownian objects get their
behaviour via _method_ functions.  If you download the source code for ape
from CRAN and have a look in PGLS.R you will see a bunch of functions such
as Initialize.corPhyl and corMatrix.corBrownian which are methods for
Initialize and corMatrix for corPhyl classes and corBrownian classes
respectively.

 So when you come to use one of these correlation structures, the calling
code doesn't care how the correlation structure computes its correlation
matrix, it just calls the corMatrix function and the object-oriented magic
calls the specific one for that specific class of model.

 So in ape, all the phylogenetic correlation classes are initialised with
Initialize.corPhyl and the Brownian one has corMatrix.corBrownian as the
method for computing its correlation matrix. You can see the source code
for these methods by typing their names on the R command line. Sometimes
methods aren't exported and aren't so easily visible on the command line,
leading to frustration. Download the source package for complete
satisfaction.

 The help for ?corClasses in the nlme package has a bit more help, but you
might do well to read the source code of how these methods are created in
the ape package, especially if you are going to be creating a variation on
these phylo-classes.

 Good luck. I tried and failed to write a new corClass for nlme a few years
back.

corBlimey.

Barry

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Trouble with reading xml in R

2013-04-30 Thread Barry Rowlingson
On Tue, Apr 30, 2013 at 5:12 PM, Dorte Klerke dkle...@hotmail.com wrote:

  Hi I have been trying for days now to read the contents of this xml file into
 R. I tried the simpler solution xmlToDataFrame, which worked on another
 file, but somehow it doesn't work for this file.


 How is this possible?

 How is this possible without sending us the file? EFORGOTATTACHMENT?


 Also an extra question. My filename is called something like (a new file
 every day)

 BidAskCurves_DE-AU_20130425_20130424130349.xml

 The first part after the AU is the current date, this I can generate
 automacticly but I can't generate the last since its the date, time, minute
 and second of the time the data was uploaded from another party to their ftp
 - where I'm getting the data.

 Is there anyway to get R to find the right file, when I can only generate
 part of the file?

 The dir() function has a pattern argument, so you can do:

dir(/myfolder,pattern=BidAskCurves_DE-AU_20130425_[0-9]*.xml) # untested

to list all files that match that pattern in that folder.

the pattern is a 'regular expression', so you might have to
backslashify special characters, but - and _ aren't special.

Barry

__
R-help@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.


Re: [R] 3D Histograms on a Geographical Map

2013-04-19 Thread Barry Rowlingson
On Fri, Apr 19, 2013 at 3:13 PM, Lorenzo Isella
lorenzo.ise...@gmail.com wrote:
 Dear All,
 I like very much figure 2.a) and 2.b) of this paper

 http://www.nature.com/srep/2013/130410/srep01640/pdf/srep01640.pdf


 and I probably need a similar visualization.
 Is anything like that doable in R? I have some experience with R and
 gadm (gadm.org), but that is only to produce maps colored according to
 a scalar.
 I do not know how to visualize maps with a perspective, let alone
 adding the histograms in 3D.
 Sorry for not providing an example script, but if I had one I would
 not be posting at all.

 The panel B maps are created by using R so they are definitely
doable in R. I suspect they are using the rgl package for 3d graphics.
You just have to get the country outline data, give it a Z of 0, draw
it using the rgl 3d line functions, then add the bars (they're not
histograms) by starting at (x,y,0) and drawing a 3d line to (x,y,H)
for each value of H.

 You might try asking on R-sig-geo for more on mapping stuff with R.

 Clearly my papers don't have enough 3d nonsense graphics to get into Nature...

Barry

__
R-help@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.


Re: [R] 10% off Intro R training from RStudio: NYC May 13-14, SF May 20-21

2013-04-16 Thread Barry Rowlingson
On Tue, Apr 16, 2013 at 5:43 PM, Bert Gunter gunter.ber...@gene.com wrote:
 Hadley:

 I don't think this is appropriate. Think of what it would be like if everyone 
 shilled their R training and consulting wares here.

Everyone does, don't they? A search on Nabble shows up regular
postings from XLSolutions, Mango used to post (not seen anything in a
while) and Revo sneak the odd commercial in Dave Smith's updates.

I don't see anything about non-commercial postings being banned from
R-help, but they do seem to be against the spirit of R-help.

I suspect commercials sneak in under under 'announcements' in the
R-help documentation:

R-help: The ‘main’ R mailing list, for [...] announcements (not
covered by ‘R-announce’ or ‘R-packages’, see above)

As with everything R, if it bothers the maintainers, then they'll put
a stop to it. We users matter not...

Barry

__
R-help@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.


Re: [R] produce a map in ARCGIS from a GAM output

2013-04-12 Thread Barry Rowlingson
On Fri, Apr 12, 2013 at 10:37 AM, Lauria, Valentina
valentina.lau...@nuigalway.ie wrote:
 Hi,

 I am trying to predict the habitat suitability of lobster with GAMs. I need 
 to produce a map in ArcGis of the predicted densities. I did some search and 
 the function predict.gam seems to do the job.

 Is this the right way to do it? when you apply the function you get the 
 predicted values (different from your input data points) but I do not 
 understand what is the procedure with the spatial coordinates, I mean what 
 lat and long have the new points? Can I use the same ones of my observations?

 I suspect you'll get a better response if you:

 a) ask on R-sig-geo, the mailing list for all things R and mappy
 b) try and ask with a reproducible example - it doesn't have to be
your data, but something similar, and small, and that we can run to
get a better idea of your problem. Show us how you are running
predict.gam, at least, and what your data looks like.

To get data from R into ArcGIS you probably want to either use the
raster package to create a grid of values, or the rgdal package to
create a shapefile of point locations and estimates. Exactly how you
get that from your predict.gam results is a bit guesswork until we
know a bit more about how you are running predict.gam

Barry

__
R-help@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.


Re: [R] speedometer charts in R

2013-04-03 Thread Barry Rowlingson
On Tue, Apr 2, 2013 at 4:00 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 Look at the R GoogleVis package.

 Or read what Hadley W had to say on a similar question first:

The question would why would you want to?  You are trying to
understand your data, not driving a race car or aeroplane.  

 - 
http://r.789695.n4.nabble.com/Graphical-output-dials-and-meters-for-a-dashboard-td845090.html

But maybe you *are* creating a dashboard for an R-powered race car, in
which case here's an R-native version of the google vis speedometers:

http://gastonsanchez.wordpress.com/2013/01/10/gauge-chart-in-r/

Can't wait to see the full source code for your race car:

require(engine)
block = engine(cc=2000,cylinders=6)
require(downforce)
...

Barry

__
R-help@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.


Re: [R] edit.data() read-only?

2013-03-26 Thread Barry Rowlingson
On Tue, Mar 26, 2013 at 10:09 AM, Ted Harding ted.hard...@wlandres.net wrote:
 Greetings All.

 The function edit.data() allows a convenient spreadsheet-like
 view of a dataframe with too many rows/columns to fit on the
 screen (especially when there are many columns). Very useful
 when scanning through a dataset (row  column are conveniently
 identified by the labels at the side and above).

 Do you mean:

d=data.frame(x=1:10,y=runif(10))
edit(d)

? Because I don't have an edit.data function (maybe its windows only).

 However, there seens to be no option to set it read-only on
 start-up, with the consequence that a clumsy key-press or
 mouse-click could cause a change in the data which would then
 be stored after quitting edit.data().

 Is there a possibility of a read-only option? Or some other
 function which could offer similar viewing capability without
 the risk of data change?

 If you just want to view the data, don't assign it back. The edit
function only updates the data if you assign it back, as in:

d=edit(d)

so a 'read only' version would be:

invisible(edit(d))

except the user here can change the values in the cells, they just
don't go anywhere. Except into .Last.value if you decide you really
did want to get the values...

Barry

__
R-help@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.


Re: [R] Feedback – Regarding R Programming Language Version 2.15.1 (2012-06-22) Usage

2013-03-09 Thread Barry Rowlingson
On Sat, Mar 9, 2013 at 5:11 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 Please do not massively cross-post and provide a reproducible example
 (search stack overflow or other sites for advice on how to do so)

 I _guarantee_ you R is not broken in this sense.

 I would put money on the original post being the most eloquently
spoken yet obfuscated report of FAQ 7.31 ever.

 Barry

__
R-help@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.


Re: [R] Excel User interface for R

2013-03-05 Thread Barry Rowlingson
On Mon, Mar 4, 2013 at 1:39 PM, Tammy Ma metal_lical...@live.com wrote:

 HI,

 Assume I have the data frame generated from R as the following:

 Product Price market_share
   A 10010%
   B 1109%
  C  12020%
  D  90  61%

 What I want to do is to have this kind of excel user interface by changing 
 price of certain products, to get the impact of market share generated from R:
 if I change A price from 100 to 90, and change B price from 110 to 100, based 
 on the calculation in R, I want to get the result from excel, for example,


 Product Price market_share
   A 9020%
   B 100   12%
  C  120   10%
  D  90 58%


 I want to have the excel interface which make me be able to change the value 
 in excel cell, then based on the calculation in R, then exported market share 
 impact in excel.

 DO you have recommendation for such user interface or sth which make me 
 achieve this task?

 This is just not how you *think* in R. Formulas in Excel are all
hidden, and stuff happens automatically, and if columns are all
dependent on one another then you are redundantly storing information.

 If I was doing a table like this I would only store the original
information, and then write some functions to produce the spreadsheet
with all the derived columns. I would only change the original
information, and then re-run the function that generates the report.

 Now, I really don't understand in your example how changing the price
of A from 100 to 90 results in a change of market_share from 10% to
20%, so I guess there must be some complex formula going on. I'll
simplify

 Suppose your data is Product, Price, and Unit Sales:

  d = 
  data.frame(Product=c(A,B,C,D),Price=c(100,110,120,90),Sales=c(3,5,3,7))
  d
  Product Price Sales
1   A   100 3
2   B   110 5
3   C   120 3
4   D90 7


 And in Excel you would normally compute market share by value as
100*Price * Sales / SUM(Price*Sales). Then in R:

  d$ShareByValue = 100 * d$Price * d$Sales / sum(d$Price*d$Sales)
  d
  Product Price Sales ShareByValue
1   A   100 3 16.30435
2   B   110 5 29.89130
3   C   120 3 19.56522
4   D90 7 34.23913

But if the price of Product A was wrong, and you have to change it to
90, then yes, you have to re-run the function:
  d$Price=90
  d$ShareByValue = 100 * d$Price * d$Sales / sum(d$Price*d$Sales)
  d
  Product Price Sales ShareByValue
1   A90 3 16.7
2   B90 5 27.8
3   C90 3 16.7
4   D90 7 38.9

But now we can get a bit smarter. Let's write a function that computes
the share by value:

 computeShare = function(d){100*d$Price*d$Sales/sum(d$Price*d$Sales)}
  computeShare(d)
[1] 16.7 27.8 16.7 38.9


 So we just have to do:

  d$Share = computeShare(d)

and we can re-use that function on other data (with the same named
columns). If there are any bugs in that function they only need fixing
in one place. Yes, if your data changes then all your columns may need
adjusting, but you just write a script or a function that does it. I
think something like this:

 updateSales = function(d){
  d$Share = computeShare(d)
  d$TotalItemCost = totalItemCost(d)
  d$Tax = taxTate*d$TotalItemCost
  totalTax = sum(d$Tax)
 list(data=d,totalTax=totalTax)
}

is a lot easier to understand than hunting round spreadsheet cells to
find that one formula you typed in wrong...

Barry

__
R-help@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.


Re: [R] Commercial or not?

2013-02-21 Thread Barry Rowlingson
On Thu, Feb 21, 2013 at 9:52 AM, Pancho Mulongeni
p.mulong...@namibia.pharmaccess.org wrote:
 Hi All,
 Let's say someone uses an R package (prefer to not disclose which) that comes 
 with two different distributions,the commercial and non-commercial license. 
 Now the non commercial license has conditions,bit it never runs out. So if 
 this person knows they should be using the commercial license, because they 
 are not a student and are paid for their work , (ie they are outside the 
 non-commercial license) how can one convince management at the 
 institution/company/not for profit to buy the commercial one? Is it even 
 necessary? Thanks.

 If the non-commercial license never runs out, then that's irrelevant
to commercial use.

 If the user knows they should be using the commercial license, then
yes, they should buy the commercial license. Even if they don't know
they should be using the commercial license. Ignorance of the law is
no excuse.

 How do you convince company management to buy licenses? Point them to
any news stories about being raided by the BSA. The inconvenience will
probably cost more in downtime than license fees. Or show them that
the package you want to use is cheaper than other commercial
solutions. Or do a cost-benefit analysis (Reimplementing these
methods will take X hours = Y dollars  Cost of Package).


Standard I am not a lawyer but I had a law PhD girlfriend and used to
read her legal theory books disclaimer applies.

Barry

__
R-help@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.


Re: [R] Cramer von Mises test for a discrete distribution

2013-02-20 Thread Barry Rowlingson
On Wed, Feb 20, 2013 at 10:03 AM, Santiago Guallar sgual...@yahoo.com wrote:
 Thanks Barry,

 Following your list order
 1) It pops up a window saying R for windows GUI front-end crashed. Below
 three options: look for on-line solutions; shut down the program; debug the
 program (I'm translating from Spanish)

 That's good - often people say crash when all they have seen is a
stop from R.

 2) The processor of my laptop is an Intel Core duo 1,60GHz with ram= 4 GB,
 32 bits. The R version I have installed is 2.15.2 (2012-10-26)

 Nicely up to date...

 3) I read the posting-guide. Ok, it may be basic statistics. Question
 withdrawn

 Oh don't do that! You're not asking how to do basic statistics, you
are trying to do it yourself and getting a crash. Fair question for
starters...

 I made an additional mistake: I attached the wrong files. Please run the
 code with these, and you'll see the problem.

 Will I, will I, will I

 ct1 = cvmts.test(prm, prpmr) # here R crashes

 *** caught segfault ***
address 0x5620e458, cause 'memory not mapped'

Traceback:
 1: .C(CvMTestStat, as.double(x), as.integer(length(x)),
as.double(y), as.integer(length(y)), testscore = double(1))
 2: cvmts.test(prm, prpmr)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:

Yes! This looks like a bug in that package function, a bit of
investigation seems to blame it on when you have repeated values in
the vectors:

 cvmts.test(1:10,1:10)
[1] 0.025
 cvmts.test(rep(1,10),rep(1,10))
[1] 0.955
 cvmts.test(rep(1,10),rep(2,10))

 *** caught segfault ***
address 0x514daba8, cause 'memory not mapped'

Traceback:
 1: .C(CvMTestStat, as.double(x), as.integer(length(x)),
as.double(y), as.integer(length(y)), testscore = double(1))
 2: cvmts.test(rep(1, 10), rep(2, 10))

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

Functions shouldn't crash like this - so time for you to email the maintainer:

 packageDescription(CvM2SL2Test)$Maintainer
[1] Yuanhui Xiao yx...@gsu.edu

The function disappears into C code, but I suspect its dividing by
zero somewhere...

Barry

__
R-help@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.


Re: [R] Cramer von Mises test for a discrete distribution

2013-02-19 Thread Barry Rowlingson
On Tue, Feb 19, 2013 at 2:49 PM, Santiago Guallar sgual...@yahoo.com wrote:
 Hi,

 I'm trying to carry out Cramer von Mises tests between pairs of vectors 
 belonging to a discrete distribution (concretely frequencies from 0 to 200). 
 However, the program crashes in the attempt. The problem seems to be that 
 these vectors only have positive integer numbers (+ zero). When I add a 
 random very small positive decimal to the non-decimal part everything works 
 fine (files prm1  prpmr1). I attach two of these vectors so you can run the 
 following code. I've also thought to divide both vectors by a real constant 
 such as pi. Do you think these two approaches are acceptable?
 
  setwd()
  require(CvM2SL2Test)
  prm = scan('prm.txt')
  prpmr = scan('prpmr.txt')
  ct1 = cvmts.test(prm, prpmr) # here R crashes

 For you maybe. For me, works fine, and:

  ct1

[1] 30.20509

  cvmts.pval( ct1, length(prm), length(prpmr) )

 - this is taking a bit longer. I gave up and killed it. Maybe it
would have eventually crashed R, but you said the other function
call crashed R.

Your two mistakes are:

 1. Saying R crashes without showing us any kind of crash report or
error message.
 2. Not listing your system and package versions.

Ah, your three mistakes are...

 3. Not reading http://www.r-project.org/posting-guide.html


Barry

__
R-help@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.


Re: [R] Help with functions as arguments

2013-02-12 Thread Barry Rowlingson
On Tue, Feb 12, 2013 at 7:30 AM, Ian Renner ian_ren...@yahoo.com wrote:

 Where I am running into trouble is when I want to call function f1 within 
 function f2:

 f2(x = 3, z = f1(x))

 This returns the error:

 Error in f1(x) : object 'x' not found

 I'm not sure how to define environments within the functions so that the 
 just-defined 'x' may be passed as an argument to f1 within f2.

I think this is a bit like the joke where a man goes to the doctor,
raises his arm up and says It hurts when I do that, and the doctor
says well, don't do that then. Next patient!.

Whatever is calling f2 knows what it is passing as the first argument.
It should then know that it wants to pass f1(the first argument) and
so can explicitly put that into the first argument of the f1 call. ie.
your example should be;

f2(x=3, z=f1(3))

What you are trying to do is akin to saying:

f2(x=3, z=f1(that thing I passed to the x parameter, you expect me to
type it in again? I thought computers were supposed to save effort!))

Now, this is different to *defining* f2 to take f1(x) as the default
second parameter to f2:

f2 = function(x,z=f1(x)){y=x*z-2;y}

which is saying that unless the user says otherwise when they call
this function, the second parameter is f1(the first parameter). This
does work as expected.

But the crux is that the terms inside function calls are not executed
as assignments like you thought they were. For one thing, named
function parameters can appear in any order - would you expect x be
defined in the f1(x) if you called f2(z=f1(x),x=9)?

Barry

__
R-help@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.


Re: [R] Deques in R

2013-02-11 Thread Barry Rowlingson
On Mon, Feb 11, 2013 at 5:20 PM, Michael Holt mh...@terapeak.com wrote:
 I've been searching for information on using deques in R for the past couple 
 of days. What little I've found has pointed me towards either the Rcpp 
 package or the cpp project on R-forge 
 (https://r-forge.r-project.org/projects/cpp/), but I've had trouble finding 
 working examples. Are these the best ways to go about trying to implement a 
 deque in R and does anyone have examples of how to do so?

 [[alternative HTML version deleted]]

 __
 R-help@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.

It appears there was a package called Containers that implemented a
deque (and other things):

http://cran.uvigo.es/web/packages/Containers/

but I can't find it on CRAN now...

http://cran.r-project.org/web/packages/Containers/

so you could hook the code out of the archives and find out if it still works...

Barry

__
R-help@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.


Re: [R] Deques in R

2013-02-11 Thread Barry Rowlingson
On Mon, Feb 11, 2013 at 9:42 PM, Barry Rowlingson
b.rowling...@lancaster.ac.uk wrote:

 but I can't find it on CRAN now...

 http://cran.r-project.org/web/packages/Containers/

 so you could hook the code out of the archives and find out if it still 
 works...

 I just looked at the DESCRIPTION and it depends on rJava, and it
appears to be a bunch of wrappers to Java classes and code to do the
real work. Eeeyuck.


Barry

__
R-help@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.


Re: [R] help with creating new variables using a loop

2013-02-07 Thread Barry Rowlingson
On Thu, Feb 7, 2013 at 4:16 PM, christel lacaze
christellac...@hotmail.co.uk wrote:

 Hi there,

 I've got a set of 10 numeric variables called Mood1 to Mood10 in a dataset 
 called mood.

 That's where you went wrong in the first place. Don't use variable
names for indexing purposes.

 You should have created one variable, a list, where each element is
one of your Mood1, Mood2 etc variables. You can do that:

Mood = list(Mood1,Mood2,Mood3 [etc])

 but its easier to create the right thing in the first place.

 Then looping is simple, and intuitive. Just get Mood2[[i]] where i is
your loop variable. No mucking with paste and get and all that stuff
we should have left behind years ago...

  I'm trying to create a set of 10 new variables called m1 to m10 so that 
 m1=Mood1*1, m2=Mood2*2, etc to m10=Mood10*10

 What you mean is you want to create a new variable, a list, with 10 elements.

 m = list()
 for(i in 1:10){m[[i]]=i*Mood[[i]]}

or even:

 m = lapply(1:10,function(i){i*Mood[[i]]})

this kind of thing is so much easier once you've put everything in an
indexable list, I'm not going to tell you how to paste names together.
It can be done, but... yuck.

Barry

__
R-help@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.


Re: [R] developing package: dealing with namespaces

2013-02-04 Thread Barry Rowlingson
On Mon, Feb 4, 2013 at 6:23 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote:
 On 04/02/2013 12:59 PM, Ross Boylan wrote:
 I am tweaking an R package for which I have the source; the relevant code
 is in R not C.   I'm making changes to the package code.

 What is the best workflow for doing this?  I recall the advice used to be
 to remove the NAMESPACE during development, but I don't think this is
 possible anymore.

 For simplicity, suppose I have an outer level function f defined in f.R
 and an innder g in g.R defined in the package.

 My understanding is that if I modify g.R and load it (e.g., C-c C-l in
 ESS) this will have no effect on the code the f calls, since the latter is
 in a namespace.

 If I modify f.R and import it, I'm not sure if it can find g at all if it
 has not been exported.

 Web searches and reviewing the R Extensions manual have turned up
 information on how to trace into functions in namesapces, but not on the
 larger development cycle.

 I think the best workflow is to do the edits outside of R, and
 re-install the package to test.

Isn't the best[1] workflow to use devtools? Edit the code in-place, do
load_all(packagefolder) and devtools' magic does the rest? Without
polluting the workspace.

Since I started doing that I hardly ever C-c C-l into ESS any more.
All my functions are in packages, sometimes the package is just
created ad-hoc with devtools' create(packagefolder) function.
Lightweight, yet fully-functional packages. Dream.

Barry

[1] for some value of best

__
R-help@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.


Re: [R] Modify objects in function

2013-01-31 Thread Barry Rowlingson
On Thu, Jan 31, 2013 at 11:52 AM, Simon Zehnder szehn...@uni-bonn.de wrote:
 Dear R community,

 I do know, that an R function is constructing a copy of any object passed as 
 argument into a function. I program on a larger S4 project for a package, and 
 I arrived at a point where I have to think a little harder on implementation 
 style (especially to spare users complex object handling).

 I have a function foo(), taking as input arguments two S4 objects of 
 different class type

 foo - function(o1, o2) {
 o1@att1 - producesomething()
 o2@att2 - producesomethingelse()

 }

 Of course, this functions does not change the objects in the global 
 environment. Now I have two choices

 1. Change the objects and return a list with both objects:

 foo - function(o1, o2) {
 o1@att1 - producesomething()
 o2@att2 - producesomethingelse()

 l - list(O1 = o1, O2 = o2)
 return(l)
 }

 This is cumbersome for users, as they have then to assign the objects inside 
 the returned list to the symbols used in the global environment. But it is 
 the way intended by R.

By cumbersome you mean the following (anti-?) pattern has to be used,
for example in a loop:

 o1 = something()
 o2 = somethingelse()
 o12 = foo(o1,o2)
 o1 = o12$o1
 o2 = o12$o2

so that at the end of it you have a modified o1 and o2?

 I suggest that if you have a function that modifies more than one of
its arguments, then there is a strong case for making those arguments
a single argument. So that you'd do:

 foo = function(o12){
o12$o1@att=bar()
o12$o2@att=baz()
return(o12)
  }

 o12 = list(something(), somethingelse())
 o12 = foo(o12)

and there you are, a modified o12 object. no packing/unpacking needed.

 I suspect that either your o1 and o2 are so closely related that you
should pack them in a list (or ideally, an object) or differently
related such that you should treat them separately and not tweak both
of them within the same function. That approach is binding behaviour
very tightly to two structures, and probably won't give you very
debuggable modular code.


B

__
R-help@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.


Re: [R] Modify objects in function

2013-01-31 Thread Barry Rowlingson
  it lets you do:

  (a~b~c) = foo()

Mistook. should be:

(a~b~c) %=% foo()

 because it defines the %=% operator.

Barry

__
R-help@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.


Re: [R] Modify objects in function

2013-01-31 Thread Barry Rowlingson
On Thu, Jan 31, 2013 at 3:00 PM, Simon Zehnder szehn...@uni-bonn.de wrote:
 Hi Barry,

 this actually a good idea, to put them together! Probably even creating an 
 object containing both of them. Haven't thought about it before.


 Hadley W asked for implementations of 'unstructuring assignments' the
other day, and I bashed this out to a gist:

https://gist.github.com/4543212

 it lets you do:

 (a~b~c) = foo()

and if foo() returns a list with three components it assigns them to
a, b, and c. Equivalent to:

tmp = foo()
a=tmp[[1]]
b=tmp[[2]]
c=tmp[[3]]

whether its any use to your use case or even works properly under all
circumstances or even just serves to obfuscate things is a point for
discussion...

Barry

__
R-help@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.


Re: [R] Approximating discrete distribution by continuous distribution

2013-01-22 Thread Barry Rowlingson
On Tue, Jan 22, 2013 at 11:49 AM, Michael Haenlein
haenl...@escpeurope.eu wrote:

 I would like to find a continuous approximation of this discrete
 distribution in order to estimate the probability that a person is for
 example 16 years old.

 Given that people age continuously (and continually...), you sound
like you are trying to replace one discrete distribution with another
(discretised by year).

 A continuous distribution would give you, for example, the
probability that a person is between 16.0 and 16.1 years old.

Barry

__
R-help@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.


Re: [R] Access data from URL

2013-01-21 Thread Barry Rowlingson
On Mon, Jan 21, 2013 at 12:36 PM, R_Antony antony.akk...@ge.com wrote:
 Hi all,

 i need a small help that i want to access data from a url.
 i tried with
 read.table(URL,header=TRUE) - but getting errors. actually no idea that how
 can be done. I am in new in this function as well as in R.

 Could anyone please help me out, how we can do it without installing any
 packages ?

 How about YOU help US out first. Like telling us what URL is. What
the errors are. What version of R you are using. And have you read the
posting guide?

Barry

__
R-help@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.


Re: [R] How to re-project ease( Equal Area Scalable Earth) grid with a ~25 km cylindrical projection to WGS84 0.25 degree?

2013-01-19 Thread Barry Rowlingson
On Fri, Jan 18, 2013 at 5:11 PM, Jonsson amen.alya...@bordeaux.inra.fr wrote:

 -raster(C:\\Users\\aalyaari\\Desktop\\SM_RE01_MIR_CLF31D_20100812T00_20100812T235959_246_001_7.nc,
 varname = Soil_Moisture)
 d:
 class   : RasterLayer
 dimensions  : 586, 1383, 810438  (nrow, ncol, ncell)
 resolution  : 0.2603037, 0.2916659  (x, y)
 extent  : -180, 180, -85.4581, 85.4581  (xmin, xmax, ymin, ymax)
   coord. ref. : +proj=longlat +datum=WGS84
 names   : Retrieved.soil.moisture.value
zvar: Soil_Moisture
a - spTransform(d, CRS (+proj=longlat +ellps=WGS84 +datum=WGS84
 +no_defs))
 but I got this error:

  Error in function (classes, fdef, mtable)  :
   unable to find an inherited method for function ‘spTransform’
 for signature ‘RasterLayer, CRS’


 And what is the error telling you? That there's no method for
spTransform that applies to RasterLayers.

 To transform a raster from one projection to another you need to use
projectRaster from the raster package. Note that generally this can
involve warping a raster and interpolating the new values to get a
grid of cells in the new coordinate system.

 But... you were trying to do this:

 a - spTransform(d, CRS (+proj=longlat +ellps=WGS84 +datum=WGS84  +no_defs))

where d was:

 coord. ref. : +proj=longlat +datum=WGS84

 - which is a no-op. The source and destination have the same
coordinate reference system. You need to tell raster what the
coordinate system of the source is. See ?projection - note this
doesn't change the raster or do any projection, its just to tell the
system what the coordinates in the data represent - lat,long or metres
or whatever..

I looked in the HDR file and saw nothing about the projection, so I
don't know how to specify what you've got.

 Also, you didn't point us to the .nc file you used in your example.

Also also, you should probably be posting to R-sig-geo.

Barry

__
R-help@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.


  1   2   3   4   5   6   7   >