Re: [R] Can we prepare a questionaire in R

2011-06-08 Thread Barry Rowlingson
On Wed, Jun 8, 2011 at 12:56 PM, amrita gs ammasamri...@gmail.com wrote:
 How can we create HTML forms in R

 HTML is Just Plain Text, so you can create them using R's text output
'cat' function. E.g.

cat('form First name: input type=text name=firstname /br
/Last name: input type=text name=lastname //form',
file=test.html)

 and job done. Open test.html in your web browser and there it is.

 Other packages may help you construct these things - search CRAN for
html, and also 'brewer' which is a handy package for making templates
which you can render into HTML.

 But to be honest, your question is way too general as stated to get a
decent response here.

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] Problem with package development

2011-06-03 Thread Barry Rowlingson
On Fri, Jun 3, 2011 at 11:51 AM, Sarah Goslee sarah.gos...@gmail.com wrote:

 If you don't recognize the official r-project.org R-admin manual as a 
 legitimate
 link then I'm afraid I also can't help you any further since there is nothing
 more legitimate than the official documentation.

 Except the source code! Possible case in point, someone on
StackOverflow was wondering why 0 = x = 1 isn't a valid
expression, neither in the context of what he expected (TRUE if x is
between 0 and 1) nor how I explained it would function (as (0=x) =
1, and then comparing a TRUE/FALSE against 1) if it were not for the
flagging of comparison operators as non-associative in gram.y in the
source code. I even recompiled R with = as left associative to check.
Sure enough, I could then type 0 = 5 = 1 as a valid expression and
get TRUE returned.

 Now, the user (eventually) understood all of this, but neither he nor
I could find this documented in the R docs. Actually, it sems to
contradict the code [my **emphasis**]:

The exponentiation operator ‘^’ and the left assignment operators ‘-
- = -’ group right to left, **all other operators** group left to
right. That is, 2 ^ 2 ^ 3 is 2 ^ 8, not 4 ^ 3, whereas 1 - 1 - 1 is
-1, not 1. .

 Shortly before that the comparison operators (,  etc) are listed in
a table of precedence with the other operators.

 Actually I reckon this is a clear documentation bug and I should
probably report it... But its lunchtime and there's free cheese...

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] Value of 'pi'

2011-05-30 Thread Barry Rowlingson
  For an engineer, assuming that pi = 3.142 will
  probably enable him to build a very satisfactory
  bridge. Assuming that pi = 3.14159265358979323844
  will give the circumference of the Earth's orbit
  to one millionth of a millimetre. 

 And just a few more decimal places will get you the circumference of
the universe accurate to the size of a proton:

http://www.trans4mind.com/personal_development/JavaScript/longnumAstronomical.htm

 Neglecting Einstein, of course.

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] Changing the name of the R process in top

2011-05-29 Thread Barry Rowlingson
On Sat, May 28, 2011 at 7:48 PM, Matthew Keller mckellerc...@gmail.com wrote:

 Perhaps this is more of a unix question, but I'll give it a try here.
 I am running 9 different R processes at the same time (called from a
 shell script using R CMD BATCH).  When I use the top program to
 monitor how they are doing, it is impossible to tell which R process
 is related to which R script. Is there a way to rename a specific
 instantiation of an R process in top with another, more informative
 name, e.g., something like R-script1 R-script2 etc?

 man prctl:

  PR_SET_NAME (since Linux 2.6.9)
  Set the process name for the calling process, using the
value in the location pointed  to  by  (char *)
  arg2.  The name can be up to 16 bytes long, and should
be null terminated if it contains fewer bytes.

 so if you have a linux =2.6.9 system you can call this from some
dynamically loaded C code. Beware the 16 byte restriction, and make
sure you don't free the memory being pointed to...

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] useR! 2011 T-shirt competition

2011-05-27 Thread Barry Rowlingson
On Fri, May 27, 2011 at 5:54 PM, Albyn Jones jo...@reed.edu wrote:
 Me too, or three!

 The compo page says:

Every submitted design must be the property of the submitter, who
grants permission to the useR! 2011 conference to use the design on
the front of T-shirts distributed to conference participants if it is
chosen as the winning design.

 which doesn't stop the designer releasing the graphic under an open
license - then we can all print our own!

 I'd suggest Creative Commons License with No Modifications to stop
the SAS people producing R-LUser derivative t-shirts.

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] Get contour of a map

2011-05-24 Thread Barry Rowlingson
On Mon, May 23, 2011 at 8:00 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 11-05-23 5:55 AM, Pierre Bruyer wrote:


 I think writing that would be hard, but you can fake it.  Find the range of
 z first to work out the contour levels you want, then put very large values
 around the outside of the z matrix.  (You can't use Inf, but big finite
 values will work.)

 I had a play with this yesterday, expecting gPolygonize from rgeos to
do the heavy lifting. But all I could make it do with contours from
the standard volcano data, converted to the appropriate SpatialLines
form, was segfault. Works fine on the examples given in the
gPolygonize docs.

 That was an end-of-day ten minute experiment, so I might have another go later.

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] identical function names from 2 packages

2011-05-20 Thread Barry Rowlingson
On Fri, May 20, 2011 at 9:16 AM, Janko Thyson
janko.thyson.rst...@googlemail.com wrote:

 Yet, IMHO there will be more and more problems regarding this in the
 future as the number of contributed packages keeps growing. I personally
 would not mind at all to get used to typing 'thePackage::foo()' *all*
 the time, or at least have this as an option. In principal, this is no
 big deal once you actually *have* a true package with a namespace at
 hand. But what about the process of creating a package? AFAU, there is
 no way of simulating/emulating a namespace (which I understand is some
 special form of environment?) in order to be able to use '::' when
 creating/debugging functions that call other functions of the unfinished
 package. If anyone has some ideas on that one, I would appreciate to hear.

 there's some stuff in utils that might do it for you:

Description:

 Utility functions to access and replace the non-exported functions
 in a name space, for use in developing packages with name spaces.

Usage:

 getFromNamespace(x, ns, pos = -1, envir = as.environment(pos))

 assignInNamespace(x, value, ns, pos = -1,
   envir = as.environment(pos))

 fixInNamespace(x, ns, pos = -1, envir = as.environment(pos), ...)


See ?assignInNamespace for the full info.

Personally, I like the python way of doing things like this, and
dealing with name clashes. You can do:

 import foo

and then you do foo.bar(), foo.baz()

 or

from foo import bar

then you can just do bar(). There's also:

from foo import *

 which lets you do bar(), baz(), but is frowned upon a bit because of
possible name collisions. Or if you want to use functions with the
same name from two packages you can do:

from foo import bar as bar1
from baz import bar as bar2

 Then you can do bar1() and bar2()

 Of course if you want to change anything in the bar package then
similar hackery to the 'assignInNamespace' of R is necessary unless
you want to rebuild the python package. Often called Monkey
patching, I think, although this possibly only refers to mucking with
class objects and methods.

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] Building Custom GUIs for R

2011-05-20 Thread Barry Rowlingson
On Fri, May 20, 2011 at 7:52 AM, vioravis viora...@gmail.com wrote:

 Are there any tools currently available that enable us build GUIs??? (MATLAB
 has a GUI builder that enables the users build custom GUIs).

 Another option nobody has mentioned yet is to make it a web-based
system, and generate your dialogs using HTML FORM elements. R comes
with a basic web server engine now so it might be possible to make it
all self-contained.

 Can we make a exe of such GUI (with the R code) and let people use it
 without having to install R???

 That's another FFAQ to which the answer is usually 'no', although you
can of course distribute R alongside your application (by closely
following the terms of the R license agreement) and say in your
install notes first install R by running setupR.exe or whatever.

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] Converting the graphics window to a data matrix

2011-05-19 Thread Barry Rowlingson
On Thu, May 19, 2011 at 5:19 AM, Beutel, Terry S
terry.beu...@deedi.qld.gov.au wrote:
 I'm wondering if anyone is aware of a way to take what is visible in the
 R graphics window, pixelate it, and express that pixellation in a
 numeric matrix. For example, I am using the following command to create
 a  black (present) and white (absent) spatial simulation of grass
 tussock distribution.


 symbols(x=runif(100,-.5,1.5),y=runif(100,-.5,1.5),circles=runif(100)/30,
 inches=F,bg=1,xlim=c(0,1),ylim=c(0,1))

 What I would like to end up with is a 2 dimensional matrix that
 indicates presence/absence of grass in any given pixel as per the image
 generated from the above graphics plot.

 Instead of drawing to the screen, you can use the 'png' function to
create a graphics device that draws to an image file. Then you can
read that image file into R and get it as a matrix.

 You probably also want to set some of the margin and axis parameters
so the plotting region fills the whole device, and you dont have the
axes and tick marks etc confusing the matrix.

 That's some pointers for starters. I've not had breakfast yet...

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] Powerful PC to run R

2011-05-13 Thread Barry Rowlingson
On Fri, May 13, 2011 at 11:38 AM, Michael Haenlein
haenl...@escpeurope.eu wrote:

 I'm now thinking about buying a more powerful desktop PC or laptop. Can
 anybody advise me on the best configuration to run R as fast as possible? I
 will use this PC exclusively for R so any other factors are of limited
 importance.

 Michael Haenlein
 Assocaite Professor of Marketing

 As a Professor of Marketing surely you buy whatever Apple tell you to?

 Seriously, 'as fast as possible'? No financial constraints? Then
spend several billion in a factory and some hardware developers to run
R on bare silicon. Too much? Spend a million on a data centre and
stuff it full of rack servers, and some software developers to make
your algorithms run in parallel on the cluster.

 Secondly, speed is massively dependent on exactly what you are doing.
Some jobs are I/O-bound, they can only go as fast as they can read in
or write out data. Some are limited by available RAM, and start
swapping bits of memory to hard disk, slowing things up. Some are
CPU-bound and can go faster by plugging in a faster processor. Some
are bound by internal bus speeds, and can't shuttle information
between RAM and CPU fast enough. The solution to each of these
problems is different. For example, there's no point in buying an
8-core CPU if your programs can only use 1 core at a time, and you
don't think you'll be running 8 programs at once.

 Conclusion: for a desktop PC, get as much fast RAM, the fastest CPU
and the quickest HD you can find. That should cover all the possible
bottlenecks.

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] vector file

2011-05-01 Thread Barry Rowlingson
On Sun, May 1, 2011 at 8:08 AM, azam jaafari azamjaaf...@yahoo.com wrote:
 Dear All

 I want to import the vector file (   .shp) to R. I could import the file by 
 rgdal package before, by following:

 geology-readOGR('C:/geology//saga/geo.geom','finalgeology')

 but now there is an error:

 Error in ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding = 
 input_field_name_encoding) :

     GDAL Error 4: .shx file is unreadable, or corrupt.

 Can you tell me where is the problem.

 I would say that the .shx file is unreadable, or corrupt.

Do you even have a .shx file? For every .shp file, there should be a
.shx file, and a .dbf file. .shp files on their own are useless - you
will need at least finalgeology.shp, finalgeology.shx and
finalgeology.dbf. There may also be a finalgeology.prj with the
projection info.

 We don't know what's changed between when you said it worked and now,
so we can't really tell. The only clue is the error about the .shx
file - so check you still have the .shx file and you didnt delete 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] setting options only inside functions

2011-04-27 Thread Barry Rowlingson
 but it's a little clumsy, because

 with_connection(file(myfile.txt), {do stuff...})

 isn't very useful because you have no way to reference the connection
 that you're using. Ruby's blocks have arguments which would require
 big changes to R's syntax.  One option would to use pronouns:

 Looking very much like python 'with' statements:

http://effbot.org/zone/python-with-statement.htm

 Implemented via the 'with' statement which can operate on anything
that has a __enter__ and an __exit__ method. Very neat.

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 program with colleagues

2011-04-19 Thread Barry Rowlingson
On Tue, Apr 19, 2011 at 6:20 PM, Alaios ala...@yahoo.com wrote:

 b. Could you please suggest me an easy way to exchange the R code with my 
 colleagues. I know about these version systems but unfortunately they look 
 pretty bizarre to me.

 Nothing looks more bizarre than a project that isn't using version
control. You end up with files like 'modelfit-daves-version.R',
'workedOnThursday.R', and 'daves-version-worked-on-Thrusday-0022.R'.

 Use Mercurial (hg), and force the team to use it. Only through
force will the team realise it is a Good Thing. You can get private
hosting for Mercurial on BitBucket for a small number of
people/projects. If your code is open you can have as many projects as
you like. Or you can pay for hosting.

 You may also want to decide on coding style (so that Fred isn't
continually re-indenting Dave's code with three spaces instead of
four). If you are developing a package the most of the directory
structure is decided for you, but you might also want to use Roxygen
for documentation.

 The important thing is to get it right at the start, since it can be
a pain to implement many best practices after the team has been doing
it wrong for a while.

 And obviously +1 for writing tests, and use git if anyone prefers it to hg.

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] URL Scan

2011-04-18 Thread Barry Rowlingson
On Sun, Apr 17, 2011 at 11:56 PM, jmsc michaelfp...@gmail.com wrote:
 The site does not require a login/password. Another way to access the first
 site would be to go to the second site, click Connecticut, click Canterbury,
 CT, enter the online database, click search under Query by Location with
 nothing in the search fields, and click the first property. Viewing the
 frame source on this page redirects to the second site.

 it doesn't require a login/pass, but it uses session cookies to
simulate a logged-in user (there's even a log out button that clears
the session).

 Also, could you direct me to or give me some instructions on scanning from
 sites that do require a login/password? Thanks.

 I had a quick look for R-help posts on this ( RSiteSearch(cookies),
RSiteSearch(session) etc) but didn't find much. You probably want to
install  RCurl and look at the examples.

 Generally what happens is that a successful login, or in this case
just visiting the database front page, causes the web server to send
back a 'cookie' with a long ID number in it. For every further access
to that web site your browser includes the cookie. The server then
looks up the ID, goes 'yup, this is a valid session', and sends you
the page you want. If the cookie isn't there, or the ID isn't valid
(and the ID numbers are big enough to make guessing impractical), then
you get the default page.

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] URL Scan

2011-04-17 Thread Barry Rowlingson
On Sun, Apr 17, 2011 at 9:40 PM, jmsc michaelfp...@gmail.com wrote:
 I am wondering why when I try to input data from the first site listed below
 into R using the scan() function, a different page is read in instead (the
 second site listed):

 http://data.visionappraisal.com/CanterburyCT/parcel.asp?pid=1242

 http://www.visionappraisal.com/databases/

 I am wondering if this is an issue with R or something in the source code of
 the web page that I am not familiar with. Since I can access the first site
 directly, I assume it is not within the source code. Any help would be
 appreciated.

 I can't access the first URL directly - even from my web browser
without R being involved at all. Is that pid a parcel ID that you
need to be logged in to see? Or not a valid parcel id anymore?

 If you want to access a web site from R that needs a login/password
then you need to send the appropriate login form info from R and keep
the cookie session info that gets returned. Web sessions from R and
from a web browser are independent.

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 plots pdf() does not allow spotcolors?

2011-04-13 Thread Barry Rowlingson
2011/4/13 Matthieu Stigler matthieu.stig...@gmail.com:
 Jim

 Thanks for your feedback! The problem is that the people those responsible
 for layout are us... We are doing the book in Latex, and till now did not
 need any other software.

 But I am scared we will need use kind of Indesign  co softwares to be able
 to use our R plots, since R can't export into spotcolor...

 I've just had a look into how PostScript handles spot colours, having
been hacking PS files for many years its not something I'd played with
before.

 This page gave me a PS file that used spot colours:

http://pslib.sourceforge.net/examples.php

and it seems that you can set a colour using a colour space array:

[ /Separation (PANTONE Violet C)
  /DeviceCMYK { dup 0.75 mul exch dup 0.94 mul exch dup
0.00 mul exch 0.00 mul }
] setcolorspace 1.00 setcolor

Now, my screen previewer has no idea what colour PANTONE Violet C is,
so there's an alternative CMYK colour space version. In fact PANTONE
Violet C is just a label. The idea is that when processed for colour
separations the software will use the separation colours.

Now, to get this into R is tricky. Either you have to rewrite the PS
driver or hack the PS output file. I produced a simple R plot with one
purple (col=#FF00FF) blob and saved to a PS file. The bit of the PS
that set the colour was this:

 /bg { 1 0 1 rgb } def
 1 0 1 rgb

 - the two settings here are for the outline and fill of the blob,
which was created using pch=19.

 To specify this as a spot colour (with a CMYK alternative for
preview), I changed that to this:

/pvc {
[ /Separation (PANTONE Violet C)
  /DeviceCMYK { dup 0.75 mul exch dup 0.94 mul exch dup
0.00 mul exch 0.00 mul }
] setcolorspace
} def

/bg {
pvc 1.00 setcolor
} def
pvc 1.00 setcolor

Now if you only have one or two spot colours and only a few places
where they occur then it might be possible for you to do this kind of
edit/replacement - either manually or automatically. And beware I'm
not even sure this is right or that your publisher would be happy
anyway.

 Anyway, thats enough PS hacking for one day.

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 plots pdf() does not allow spotcolors?

2011-04-13 Thread Barry Rowlingson
On Wed, Apr 13, 2011 at 5:26 PM, Jeremy Hetzel jthet...@gmail.com wrote:
 Scribus claims to be able to convert RGB/CMYK colors to spot colors:
 http://documentation.scribus.net/index.php/Spot_Colors

 I've never used Scribus, but it's floss.

 Scribus can import output from R's svg driver (with at least some
degree of success).

 I just imported a simple plot to Scribus, specified some spot
colours, and saved as EPS - the colours were specified as /Separation
colours as described in my earlier message.

 I did try inkscape for this, but forgot about scribus. Inkscape
doesnt seem to have such colour management.

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] nndist R vs. ArcGIS

2011-04-11 Thread Barry Rowlingson
On Mon, Apr 11, 2011 at 4:49 PM, smoluka smol...@geo.oregonstate.edu wrote:
 Can anyone tell me why I would get different average nearest neighbor values
 for the same set of coordinates between ArcGIS 10 and R? Sometimes the
 difference in distance is over 1.3 km.

 Edge correction? In a spatial point pattern, points near the boundary
of your window are less likely to have a near neighbour because only
some of the surrounding space can possibly have points. I think
functions in spatstat will correct for this.

Make a simple test example and tell us what functions you are using.

And also try the r-sig-geo mailing list  for this sort of thing.

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] best practice(s) for retrieving a local variable from a closure

2011-04-09 Thread Barry Rowlingson
On Sat, Apr 9, 2011 at 6:29 PM, Benjamin Tyner bty...@gmail.com wrote:

 The above feels a bit like snooping where I wasn't invited.
 You could do something like
  mq - function(a) {
     force(a)
     list(getA = function()a,
          setA = function(newA) a - newA,
          fun = function(x)x^a
     )
  }
 to make it clear that you expect people to look at or change
 fun's 'a'.

 Once you start doing a lot of that though you may as well go the
whole OO hog and use the proto or R.oo 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] MySql Versus R

2011-04-01 Thread Barry Rowlingson
On Fri, Apr 1, 2011 at 11:46 AM, Henri Mone henrim...@gmail.com wrote:
 Dear R Users,

 I use for my data crunching a combination of MySQL and GNU R. I have
 to handle huge/ middle seized data which is stored in a MySql
 database, R executes a SQL command to fetch the data and does the
 plotting with the build in R plotting functions.

 The (low level) calculations like summing, dividing, grouping, sorting
 etc. can be done either with the sql command on the MySQL side or on
 the R side.
 My question is what is faster for this low level calculations / data
 rearrangement MySQL or R? Is there a general rule of thumb what to
 shift to the MySql side and what to the R side?

 Given that you are already set up to test this yourself, why don't
you? SELECT everything from a table and add it in R, and then SELECT
sum(everything) from a table and compare the time (obviously your
example might be more complex). Post some benchmark test results
together with your hardware spec. Probably best to the db-flavour R
mailing list.

 Is the MySQl server running locally, ie on the same machine? Maybe
PostgreSQL will be even faster? So many of these questions are
problem-specific and hardware-setup related. You can get massive
speedups by having more RAM, or more disk, or spreading your giant
database onto multiple servers.

 Rules of thumb are rare in this world, since everyone's thumbs are
different sizes and are being stuck into different sized problems.

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] colour palette for positive/negative range

2011-03-18 Thread Barry Rowlingson
On Fri, Mar 18, 2011 at 3:37 PM, Frank Schwach f...@sanger.ac.uk wrote:
 Hi,

 I'm plotting a heatmap with values ranging from -10 to +10 and I would
 like the negative values to show up in shades of blue and the positive
 ones in shadea of red. Basically, I want exactly what the RColorBrewer
 palette RdBu does but with more of a gradual change (the RdBu can only
 give me 11 distinct colours). Any suggestions?

 Use RColorBrewer along with my colourscheme package
[https://r-forge.r-project.org/R/?group_id=435] to interpolate between
them:

library(RColorBrewer)
bp = brewer.pal(11,RdBu)
library(colourschemes)
cs = rampInterpolate(c(-10,10),bp)

now cs is a function that interpolates the 11 palette colours so you
have a continuous colour palette. Note the interpolation is (umm I
think) linear in R G and B.

s=seq(-10,10,len=100
plot(s,s,col=cs(s),pch=19)

gives you 100 different 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] Why doesn't this work ?

2011-03-17 Thread Barry Rowlingson
On Thu, Mar 17, 2011 at 3:54 AM,  bill.venab...@csiro.au wrote:
 It doesn't work (in R) because it is not written in R.  It's written in some 
 other language that looks a bit like R.

 It parses in R, so I would say it was written in R.

 To paraphrase Obi-wan, it's just not the R you are looking for.

__
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] Does R have a const object?

2011-03-16 Thread Barry Rowlingson
On Wed, Mar 16, 2011 at 4:16 PM,  luke-tier...@uiowa.edu wrote:

 That would defeat the purpose.  Unlocking things in base may be useful
 for experimenting or debugging but it is not a good idea otherwise.

 You are making experimenting in R more awkward? Then I'm throwing
That would defeat the purpose straight back at you. I remember when
R was all about the experimenting. Of course it was called Splus back
then and was only available in grainy black-and-white...

 Oh well, I guess its one small step towards becoming a proper
grown-up language.

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] Make R 'Beep'

2011-03-08 Thread Barry Rowlingson
On Tue, Mar 8, 2011 at 10:01 AM, Alaios ala...@yahoo.com wrote:
 Dear all,
 I would like to ask you if R can produce any kind of sound. It would be 
 useful when code execution stops R to notify me by playing some sound.


 Is that possible in R?

If you search for 'audio' or 'sound' on CRAN's list of packages you
should find this:

http://ftp.heanet.ie/mirrors/cran.r-project.org/web/packages/audio/index.html

 - which claims to be able to play sounds. Haven't tried it myself.

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] Writing R packages in an easier way?

2011-02-11 Thread Barry Rowlingson
On Fri, Feb 11, 2011 at 7:52 AM, Dr. Michael Wolf m-w...@muenster.de wrote:
 Dear R colleagues,

 is there an easier way to write R packages for the own use - without RTools
 and TeX?

 There are simpler ways of maintaining R source code than building
packages. I bashed out a quick way of keeping code in directories as
source and reading in on demand. All you need is two functions:

import - function(dir){
  e = attach(NULL,name=dir)
  assign(__path__,dir,envir=e)
  reload(e)
  invisible(e)
}

reload - function(e){
  path = get(__path__,e)
  files = list.files(path,.R$,full.names=TRUE,recursive=TRUE,ignore.case=TRUE)
  for(f in files){
sys.source(f,envir=e)
  }
}

 Now put the source code in some folder/directory somewhere. You can
even make subdirs if you wish to organise it that way.

 I've got some .R files in lib1. I do;

  import(lib1)

 and that runs 'source' on all the .R files in there and loads them
into position 2 on the search list. ls(pos=2) shows them.

 If you edit the source code, just do reload(2) (assuming it hasn't
moved because you've loaded another package) and your stuff will be
updated. It just sources everything again. Do detach(2) to get rid of
it.

 If you want to distribute your code in source format, just make a
zip or tar of the folder with the code in, and make sure your users
have the import and reload functions (I should probably put them in a
package one day...).

 To distribute in 'binary' format, do an import, and then save as .RData:

  save(list=ls(pos=2),file=lib1.RData, envir=as.environment(2)) #
not well tested

Then your users just need to attach(lib1.RData) to get your functions.

 Now this scheme could get more complex - for example it doesn't deal
with C or Fortran code, or documentation, or tests, or examples, or
version numbering. Adding any of those would be pointless - if you
want any of that either use packages and learn to write R docs
(roxygen helps) or add it to my code yourself. You'll end up
rebuilding the R package system anyway.

 Hope this helps. Doubtless someone else will come up with a simple
way to build proper packages without all the bondage and discipline
that annoys 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] Writing R packages in an easier way?

2011-02-11 Thread Barry Rowlingson
On Fri, Feb 11, 2011 at 12:33 PM, Spencer Graves
spencer.gra...@structuremonitoring.com wrote:
 Dear Dr. Wolf:


      I understand your concern that the mechanics of writing an R package
 can be difficult.  It was hard for me when I started.

 I should add that although I did write that import/reload code for
simple development of R code in folders - I don't actually use it.
It's one of those things I wrote because someone on R-help asked a
similar question to Dr Wolf's.

 I write proper packages with examples and tests. Of course I do.

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] testing randomness of random number generators with student t-test?

2011-02-02 Thread Barry Rowlingson
On Wed, Feb 2, 2011 at 11:01 PM, Carl Witthoft c...@witthoft.com wrote:
 Hi, subject more or less says it all.

 I freely admit to not having bothered to find some of the online papers
 about method of testing the quality of random number generators -- but in an
 idle moment I wondered what to expect from something like the following:


 randa-runif(1000)
 randb-runif(1000)
 t.test(randa,randb)$p.value
 var.test(randa,randb)$p.value

 [repeat ad nauseum]


 Is the range of p-values I get in any way related tothe quality of the
 random number generator?

 Well yes. All pseudo random number generators have a period, after
which they come back to the start and begin churning out the same
sequence again. Good PRNGs have a sequence length that is
astronomically high. If you have a PRNG that has a sequence of 1000,
or 500, or 200 etc your two sets will be perfectly correlated...

 You might want to read up on RANDU, the infamous poor PRNG:

 http://en.wikipedia.org/wiki/RANDU

“We guarantee that each number is random individually, but we don’t
guarantee that more than one of them is random.”

The other things to look at are the DieHard tests:
http://en.wikipedia.org/wiki/Diehard_test

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] Unable to require installed package

2011-01-27 Thread Barry Rowlingson
On Thu, Jan 27, 2011 at 7:57 AM, 刘力平 liping.li...@gmail.com wrote:
 Hi,

 I write a package in Linux and ready to distribute, and I can install it in
 linux and run it.
 However, when I have install it in my Windows' R.

 I can not 'require' it.

 is.element(grt, installed.packages()[,1])
 [1] TRUE
 require(grt)
 Loading required package: grt
 Failed with error:  ‘'grt' is not a valid installed package’

 Is there any pitfall between platforms?
 And anywhere I could check more detailed error message.

 How did you install it in Windows? If you just copied it from the
Linux install directory, or if its in a shared directory, it probably
wont work.

 You need to do a proper R CMD INSTALL on Windows, and for that you'll
need the assorted dev tools for building R packages on Windows.

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] Movie Question

2011-01-23 Thread Barry Rowlingson
On Sat, Jan 22, 2011 at 10:07 PM, Matt Curcio matt.curcio...@gmail.com wrote:
 Greetings all,
 I am wondering if anyone is aware of any studies that draw a
 relationship between an actor and their box office gross for a movie.
 In other words, is anybody aware of any databases that contain box
 office movie grosses, actor  director info., advertising budget, etc,
 etc. [ I did a quick google search and did not find much right off but
 will keep looking.]  I would assume that movie companies, and even
 actors managers must have done or (more realistically) have access to
 statistical analysis on the average returns for any one actor,
 director, etc, etc.

 I would think that this would be a great little project.

 Did you not spot that the IMDB makes its data files available:

 ftp://ftp.fu-berlin.de/pub/misc/movies/database/

 Read the docs and check the licensing info:

 http://www.imdb.com/interfaces

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] Converting Fortran or C++ etc to R

2011-01-05 Thread Barry Rowlingson
On Wed, Jan 5, 2011 at 7:33 AM, lcn lcn...@gmail.com wrote:

 As for your actual requirement to do the convertion, I guess there'd not
 exist any quick ways. You have to be both familiar with R and the other
 language to make the rewrite work.

 To make the rewrite work _well_ is the bigger problem! The easiest
way to big performance wins is going to be spotting vectorisation
possibilities in the Fortran code. Any time you see a DO K=1,N loop
then look to see if its just a single vector operation in R.

 Another way to big wins is to write test code, so you can check if
your R code gives the same results as the Fortran (C/C++) code at
every stage of the rewrite. Don't just write it all in one go and then
hope it works! Small steps

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] real time R

2011-01-05 Thread Barry Rowlingson
On Wed, Jan 5, 2011 at 4:10 PM, Marcelo Barbudas nos...@gmail.com wrote:
 Hi,

 We're using R in an application where asking for a probability of an
 event takes about 130ms.

 What could we do to take that down to 30ms-40ms? The query code uses
 randomforest, knn.


 That's a fairly vague question So some vague answers:

 Firstly, profile your query to identify bottlenecks and then
concentrate your effort on removing them. Anything else is a waste of
time.

 Secondly, get a faster computer - whether that means faster CPU,
faster hard disks, faster RAM depends on where the bottleneck is in
your process. Or get parallel and use multiple CPUs. Or rewrite in C.
Or machine code. Or do it on a GPU.

 Thirdly, give us something more specific! Like examples perhaps?

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] problem installing R on ubuntu

2010-12-23 Thread Barry Rowlingson
On Thu, Dec 23, 2010 at 6:30 PM, Horace Tso horace@pgn.com wrote:
 Following the official instructions to install R on ubuntu 10.04, I issued 
 this command on the prompt,

 sudo apt-get install r-base

 The following packages have unmet dependencies:
  r-base: Depends: r-base-core (= 2.12.1-1hardy0) but 2.10.1-2 is to be 
 installed
          Depends: r-recommended (= 2.12.1-1hardy0) but 2.10.1-2 is to be 
 installed
 E: Broken packages

 Note I already have 2.10.1 installed.

 Ubuntu 10.4 is Lucid Lynx, so I'm slightly worried why hardy is
mentioned in the error. Is this a poorly upgraded machine from Hardy?


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] problem installing R on ubuntu

2010-12-23 Thread Barry Rowlingson
On Thu, Dec 23, 2010 at 7:15 PM, Horace Tso horace@pgn.com wrote:
 Barry, my reporting error, my ubuntu is 10.04, which is Hardy I believe. It 
 was a straight build from the source. No funny stuff done on it.

 My lsb_release says my 10.04 is Lucid.

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:Ubuntu 10.04.1 LTS
Release:10.04
Codename:   lucid

https://wiki.ubuntu.com/DevelopmentCodeNames agrees!

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 pass object members in functions

2010-12-22 Thread Barry Rowlingson
On Wed, Dec 22, 2010 at 11:20 AM, Paul Rigor pr...@ucla.edu wrote:
 Hello,
 This is an R-syntax question when attempting to manipulate/access objects
 when passed to a function.

 I have a function attempting to just print values attached to an argument
 object. For example,

 printThis - function(obj, parm2, parm3) {
   print(obj.stuff1)
   print(obj.stuff2)
 }

 where I've assigned stuff1 and stuff2 to the actual object passed as such

 actualObject.stuff1 - c(list,of,something)
 actualObject.stuff2 - c(list,of,something other thing)
 printThis(actualObject) # actual call to the function above


 But I'm getting the following error when calling the printThis method on
 actualObject.
   object 'obj.stuff1' not found

 How do I access all objects attached to a variable.  I think I'm
 misunderstanding this . (dot) where it's most likely just an acceptable
 way of naming variables in R.

 So what's the best way to create an object such that I can access what I've
 assumed to be object properties?

 Yes, dot is just an allowed character in a variable name - it doesnt
have the magical powers it has in Python or C or C++. You've created
two objects called 'actualObject.stuff1' and 'actualObject.stuff2'

 The nearest equivalent to a C struct would probably be a list with named parts:

 foo = list(a=1, b=2)
 foo$a
 foo$b

 or you need to look at the object-oriented systems in R. Be warned
that OO in R isn't much like OO in many other languages - there's at
least 3 fairly incompatible ways of doing it for starters

 Note that R objects are passed-by-value so:

 foo = list(a=1,b=2)
 bar = function(z){
   z$a=999
  }
 bar(foo)

 will leave foo unchanged.

 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] Colours for 3-way probabilities

2010-12-18 Thread Barry Rowlingson
Are there any R functions for creating palettes for three-way data?
For example, election maps for three parties where pure red, blue, and
green show 100% for the Red, Blue, and Green parties respectively,
magenta shows a 50-50 Red-Blue split with 0 for the Greens, cyan a
50-50 Blue/Green split with no Red votes and so on, with grey, black
or white at a 1/3,1/3,1/3 split vote.

I've spent a couple of half hours knocking out a function to do
various versions of that, including using Red/Yellow/Blue for the
primaries with Orange/Green/Purple for the 50/50s. I'm wondering if

 a) There's existing functionality in one of the packages on CRAN
(I've had a look and googled)

 b) Anyone can point me to information about colour perception of this
kind of three-way colour scheme.

Thanks muchly.

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] Drawing Maps of detailed Australian regions

2010-12-14 Thread Barry Rowlingson
On Tue, Dec 14, 2010 at 10:45 AM, Wang, Kevin (SYD)
kevinw...@kpmg.com.au wrote:
 Hi all,

 I'm trying to draw a bubble plot over a map -- where the map shows local 
 government areas (LGA) in Australia (or other structures under the Australian 
 Standard Geographical Classification), but am not sure where I can find the 
 data to plot such maps (e.g. draw the state of Northern Territory but also 
 showing LGA divisions).

 Any help will be greatly appreciated, apologies if this is a simple question 
 -- this is the first time I'm trying to draw a map in R :).


 A second's googling leads me to an aussie gov site with downloadable
shapefiles:

http://www.abs.gov.au/AUSSTATS/a...@.nsf/DetailsPage/1259.0.30.001July%202010?OpenDocument

shapefiles can be read in R using the rgdal package. Get that, get
'sp', get 'maptools' - get mapping!

 Any other problems, head over to the r-sig-geo mailing 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] How to ignore data

2010-12-13 Thread Barry Rowlingson
On Mon, Dec 13, 2010 at 7:36 PM, Steve Sidney sbsid...@mweb.co.za wrote:
 Oh dear oh dear!!! another arrogant statistician/scientist

 One asks for help and instead one gets an ear full!!!

 So much for the much vaunted helpful R community.

 But thanks anyway, I guess you were trying

 Steve,

 we're statisticians. we love data. we hate seeing it go to waste.
every zero, every one, every NA value is dear to our hearts. Bert was
showing the same concern that a mother does for her children. Don't
hate him for that.

  Knowing you have 100 values with about 5-10% 0/1 values is half the
story we need - if the remaining 90-95% are in the thousands then
clearly these low ones are failures, and everyone on this list will
say treat as missing values, do X = X[X1] and carry on. However if
the real values are in the tens and units then maybe something is
going on. You did say removing them hasn't affected previous analyses,
but some more data would help - we just love 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] Projecting data on a world map using long/lat

2010-12-10 Thread Barry Rowlingson
On Fri, Dec 10, 2010 at 2:21 AM, mathijsdevaan mathijsdev...@gmail.com wrote:

 Hi,

 I have a dataset (CSV) with some counts of firms located around the globe.
 Each count is assigned to the longitude and latitude of the specific
 location. Now I want to plot these counts on a world map using dots (size of
 dots represent the count). I have been unable to find any info on whether
 this is possible and if so, how? Can you please help me? Thanks!


 Plotting points is trivial - plot(data$x,data$y,pch=19,cex=data$size)
will do for a start. i'm guessing your real problem is when you say
'on a world map'.

 How detailed a world map do you need? There's an outline one in the
'maps' package, or you should be able to find a shapefile of the world
on the web somewhere and use that via the rgdal package.

 Other options include making a KML file of your points and overlaying
on google earth. Or getting google map tiles and overlaying on
that Or exporting your data to a GIS format and doing the pretty
map in something like Quantum GIS. What are you trying to do exactly?

also, you might want to post 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.


Re: [R] Remove 100 years from a date object

2010-12-10 Thread Barry Rowlingson
On Fri, Dec 10, 2010 at 3:27 PM, Daniel Brewer daniel.bre...@icr.ac.uk wrote:
 Hello,

 I have some data that has dates in the form 27.02.37.  I convert them to
 a date object as follows:
 as.Date(data$date,format=%d.%m.%y)

 But this gives me years such as 2037 when I would like them to be 1937.
  I thought of trying to take off some time i.e.
 as.Date(camCD$DoB,format=%d.%m.%y) - 100*365
 But that doesn't seem to work out correctly.  Any ideas how to do this?

Normally to adjust dates you can use as.difftime() and do arithmetic,
but a year is a variable thing (can be 365 or 366 days) so you cant
make a difftime of years. Days are variable things if you worry about
leap seconds...

Also, you could end up with an invalid date if you have 29-Feb-2000
and 29-Feb-1900. One wasn't a leap year...

A solution minus those caveats is to convert to POSIXlt and adjust the
$year element:

  dob=27.02.37
  as.Date(dob,format=%d.%m.%y)
[1] 2037-02-27
  dobp = as.POSIXlt(as.Date(dob,format=%d.%m.%y))
  dobp$year = dobp$year - 100

  dobp
[1] 1937-02-27 UTC
  as.Date(dobp)
[1] 1937-02-27

although it might be easier to paste a '19' into your character variable

  paste(substr(dob,1,6),19,substr(dob,7,9),sep=)
[1] 27.02.1937

and then do it the way you started. Assumes you have leading zeroes on
all fields though.

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] Plotting 3d surfaces

2010-12-09 Thread Barry Rowlingson
On Thu, Dec 9, 2010 at 4:20 PM, Uwe Wolfram u...@in-chemnitz.de wrote:
 Dear Subscribers,

 I am using R for quite a while nowadays on Ubuntu 10.04 LTS. I a using R
 for doing my statistics. Furthermore I am using it as a tool to generate
 the graphics for my publications.

 I am currently working on a project which involves nls-fits of three
 dimensional surfaces such as ellipsoids or even more complex. I have
 been searching R help and the manuals for a possibility to plot these
 surfaces. Is there any package in R that allows plotting something like
 this:

 http://uwwo.in-chemnitz.de/R-Problem/tsai-wu-principal-strain.pdf

 This plot was generated using Mathematicas ContourPlot3D function. I
 would love to be able to plot this in R. However, I could not find
 something which could this.

 The package you need for all things three-dimensional is 'rgl'.
Install, read docs, play!

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] GIS Help: distance calculation based on ZIP Code

2010-12-08 Thread Barry Rowlingson
On Wed, Dec 8, 2010 at 6:18 PM, XINLI LI lihaw...@gmail.com wrote:
 Thank you very much, I will look into it.

 If it really is only 200 then I'd start typing them into Google's
direction finder and typing in the distance/time given. Even if you
only do one per minute they'll all be done in half a day easily. Job
done.

 If it is going to be 20,000 then you either need a small army or some
way of automating the process. I could give you my python code that
scripted the process to both Google's Routing and an OpenStreetMap
routing service (made for some interesting comparisons), but I just
tried them again and they are both broken - probably because you're
not supposed to script these things anyway.

 Small armies are available for hire via Amazon's Mechanical Turk
service. Or find some grad students willing to do it for food.

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] Generating kml lines output

2010-11-26 Thread Barry Rowlingson
On Fri, Nov 26, 2010 at 5:03 PM, fbielejec fbiele...@gmail.com wrote:
 Dear,

 I would like to generate kml file with lines (LineString) of
 different style (definitely color, but width would also be nice to
 see). However with kmlLine from maptools package I am able only to
 output the single first Lines object (first row of
 SpatialLinesDataFrame)

 I guess the option would be to have single Lines object (instead of
 list of them), but then also the style wouldn't vary among them... My
 code so far:

 If you cant get what you want from package code, and you know a bit
about the KML format you are trying to produce, then try using the R
'brew' package, which lets your write a template which can have loops,
variable substitutions, and other bits of R code in it.

 For example, here creating a simple set of KML points from a data
frame called 'cpts':

?xml version=1.0 encoding=UTF-8?
kml xmlns=http://earth.google.com/kml/2.1;
Document
% for(i in 1:nrow(cpts)){ %
Placemark
Name%=paste(pt-,i,sep=)%/Name
Point
coordinates%=cpts[i,]$Xt%,%=cpts[i,]$Yt%,0/coordinates
/Point
/Placemark
% } %
/Document
/kml


results in a KML with lots of these:

Placemark
Namept-4/Name
Point
coordinates-43.93769,-19.92065,0/coordinates
/Point
/Placemark

 - its a lot easier than writing lots of cat() and other formatting
nonsense in R code!

 But if you can get package code to do it, that's the way to go. But
for outside-the-box solutions, install.packages(brew)!

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 call web service in R

2010-11-23 Thread Barry Rowlingson
On Tue, Nov 23, 2010 at 8:09 AM, 夏高 xiagao1...@gmail.com wrote:
 Actually RCurl is not for calling web service. But thank you all the same.
 Does anybody know how to call web service in R? Thanks!

 Use RCurl. It can be used for calling web services. A web service is
just an HTTP endpoint that returns a response. RCurl does that.

 What did you have in mind as a 'web service'?

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] extracted residuals as single column

2010-11-23 Thread Barry Rowlingson
On Tue, Nov 23, 2010 at 10:36 AM, Jennifer Dodd j.d...@bio.gla.ac.uk wrote:
 Dear list,



 I am looking for some help with the format of extracted residual values



 output from:



 residuals (model1)



 [1]  0.74140534 0.72464895 0.74873373 0.78313611 0.78836470 0.76934676
 0.77448847 0.78465077 0.79278282

 [10] 0.80852056 0.81442047 0.80890838 0.78335232 0.83127343 0.85895985
 0.85743700 0.83578769 0.82265972

 [19] 0.81611939 0.84459841 0.84346431 0.83469399 0.86057807 0.86379411
 0.84649222 0.82218322 0.61385728



 how can I change the output to a single column?



 like



 [1]      0.74140534

 [2]      0.72464895

 [3]      0.74873373

 [4]      0.78313611

 [5]      0.78836470



 etc...


 It's a single row, so to make a single column, transpose it:

t(residuals(model))

 not sure why you'd want to do that though

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] Function call on every prompt

2010-11-19 Thread Barry Rowlingson
Someone on stackoverflow.com was wondering how to display the current
time in the R prompt. I could have swore there was a mechanism for
hooking a function into R such that it is was called before the 
prompt was given, but no amount of searching in R's docs, R's source,
or RSiteSearch can find it.

 I've searched for 'hook', 'event', 'signal', and various combinations
of those with 'console', 'prompt', 'after' and 'before' with no joy.
I'm sure other people have asked this on R-help before, but I can't
find those messages either.

 Have I been hallucinating or is my search-fu week this Friday?

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] Function call on every prompt

2010-11-19 Thread Barry Rowlingson
On Fri, Nov 19, 2010 at 3:36 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:

 Barry was probably remembering SweaveHook.

 The key is the  taskCallbackManager. Does exactly what it says on
the tin.  Doesn't come up with any of my search strings!

 Hopefully now this is in R-help it'll come up when people search for
do something before every prompt.

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] Looking up the directory a file is located in

2010-11-18 Thread Barry Rowlingson
On Thu, Nov 18, 2010 at 12:00 AM, Cliff Clive cliffcl...@gmail.com wrote:

 Basically I'm just looking for a command that can look up the name of the
 directory of the script that is running.  If I move or copy the script to
 another directory, it should be able to read the name of the new directory
 without me having to edit the code.

 Once I have identified the directory, I can insert it into the setwd()
 command and continue with my program.

 This is a fairly-frequently asked question, and the questioner is
rarely satisfied with the answer.

 How is your script starting? Either:

 a) R is starting in that directory, so that the working directory is
already set, or

 b) Whatever runs the script knows where it is in order to start it,
so could pass that directory to the script somehow, either by a global
parameter, or an environment variable.

__
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] Looking up the directory a file is located in

2010-11-18 Thread Barry Rowlingson
On Thu, Nov 18, 2010 at 3:26 PM, Cliff Clive cliffcl...@gmail.com wrote:

 So it sounds like the best we can do in R is to keep track of the script in a
 sort of master file that runs the script, and set the working directory in
 the master.  Is that accurate?

 Errr no. Maybe. What?

 Your script is somewhere. Something is calling it. The thing that
calls it knows where it is. The thing that calls it is then
responsible for telling the script where it is. For example:

here = C:/Fnord/
source(C:/Fnord/script.R)

 now the script in C:\Fnord\script.R looks at 'here' and finds its
data files by pasting 'data.txt' onto the value of 'here'.

This is of course still a fairly bad way of doing things. Better to
write functions that can live _anywhere_ and tell them where to find
their data. So instead of the above, you should end up with:

 source(C:/MyLibrary/mycode.R)
 nowProcess(C:/Fnord)

where nowProcess is a function that takes a directory to work on as
its first parameter.

But EVEN better still is to write a package. Then you do:

 library(myPackage)
 nowProcess(C:/Fnord)

 In Python any time you run a script, there is a built-in __file__ variable
 that can tell you the file name of the script itself.  It would be nice to
 have a feature like this in R.

 Indeed. Also, I'd like to get rid of curly brackets from R and use
indentation, and have a neater class mechanism... Perhaps decorators
for functions... Hmm...

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] Problem downloading and opening netcdf file

2010-11-17 Thread Barry Rowlingson
On Wed, Nov 17, 2010 at 2:54 PM, D Kelly O'Day ko...@processtrends.com wrote:

 I am trying to download and open an on-line netcdf file.

 I'm using Windows XP and R 2.11.1

 Here's my script

  library(ncdf)
  link -
 http://ibis.grdl.noaa.gov/SAT/SeaLevelRise/slr/slr_sla_gbl_free_all_66.nc;
  dest -  C:/temp/slr_sla_gbl_free_all_66.nc
  download.file(url=link,destfile=dest)
  nc1 - open.ncdf(dest)

 The file appears in my C:/temp directory, however I can not open() it, I get
 this error message:

   nc1 - open.ncdf(dest)
 Error in open.ncdf(dest) :
  Error in open.ncdf trying to open file C:/temp/slr_sla_gbl_free_all_66.nc


 I can manually download and save the netcdf file and then open it. I'd like
 to be able to automate the download and open process within my script.

 Works for me. When you get the file with download.file is it
identical to when you download it from a web browser? I can only think
its getting corrupted, or perhaps your download.file isn't going
through a proxy or something and you're actually saving a proxy error
message file.

 Check the length of the saved file: file.info(dest) should help -
check the 'size' is what you expect. I get 17004 for that example.

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] Fetching data

2010-11-15 Thread Barry Rowlingson
On Mon, Nov 15, 2010 at 3:46 PM, Feng Mai maif...@gmail.com wrote:

 IMO it is not possible. The code behind aspx page queries data from a
 database server and display it on the webpage.

 That doesn't make it possible. Your web browser is sending a request
to the web server, and whatever happens behind the scenes at that end,
what comes back is a table in a web page which can be scraped.

 The tricky thing is constructing exactly the right request to get the
data you want.

 It can sometimes be as simple as constructing a url, something like
'http://example.com/price/gold/2010/11/12;, or it could need
parameters: http://example.com/price/commodity=goldyear=2010month=11;.

 Or it can be like this - some active server pages that pass a massive
VIEWSTATE object back and forth on each request. It's not impossible
to script it, but you just have a lot more mess to deal with. I have
done this kind of thing for some stupid web sites in the past. These
days people enjoy building sensible APIs to their web data.

 Oh, and it might be violating the site's terms and conditions of course.

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] Adding meta-data when creating objects. e.g: changing - so to (for example) add creation time - how-to and pros/cons?

2010-11-12 Thread Barry Rowlingson
On Fri, Nov 12, 2010 at 7:05 AM, Tal Galili tal.gal...@gmail.com wrote:
 Hello Barry,
 With regards to the identical == FALSE, it didn't occur to me - great point,
 thank you.
 So question: how did you end up changing the -, so to enable the creation
 of the .metadata object?

 I haven't done that - it's just an idea off-the-cuff that might help.
Or it might break stuff.

 What I did do was to edit assign.c (or something) in the C source of
R to keep a timestamp attribute on any assigned object. It involved
recompiling R. I suppose it could be possible to instead edit it to
put the timestamp in a global .metadata object

 However it might only be something you want done for objects in the
global workspace...

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] Adding meta-data when creating objects. e.g: changing - so to (for example) add creation time - how-to and pros/cons?

2010-11-11 Thread Barry Rowlingson
On Thu, Nov 11, 2010 at 9:37 AM, Tal Galili tal.gal...@gmail.com wrote:

 4) My real intention is to somehow change the - operator (not simply the
 assign).  I am unsure as to how to do that.
 5) Are there any major pros/cons to the adding of such meta-data to objects?
 (for example, excessive overhead on memory/performance)

 I had a go at doing (4) a few years back. The major problem I had was
that if you do:

 y - 1:10
 x - y

 with a - operator that sets a timestamp then:

 identical(x,y) is FALSE.

I implemented timestamping by adding an attribute to objects during
assigment by modifying the C source, and then lots and lots of R's
tests failed during build because identical things were no longer
identical.

Might be better to store your metadata in a separate object, .metadata
in the global env perhaps? Then just do:

.metadata[[name_of_thing]]  = list(modified=Sys.time())

in your modified assign.

Performance will only be a problem if your program is doing nothing
else except fiddle with metadata, I reckon. Your program does do
something useful, doesn't 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] Installing R and an editor on a USB drive

2010-11-10 Thread Barry Rowlingson
On Wed, Nov 10, 2010 at 10:47 AM, Hannu Kahra hka...@gmail.com wrote:

 (setq inferior-R-program-name G:/r-2.12.0/bin/i386/rterm.exe)

 since R is installed on the G drive. Everything works if R is on G, but when
 changing the computer, R is usually on another drive and Emacs cannot find
 it. Is it possible to handle this case?

There's some discussion on the portable apps list about fixing up
emacs and getting the drive letter:

 http://portableapps.com/node/12042

Using:

(defvar usb-drive-letter (substring data-directory 0 3))

to get the drive letter from emacs' data-directory variable. You could
then paste this onto the start of the path to R.

I don't have a windows box with emacs on to muck with the relevant
lisp at the moment, but I reckon something like:

(defvar usb-drive-letter (substring data-directory 0 3))
(setq  inferior-R-program-name (concat usb-drive-letter
r-2.12.0/bin/i386/rterm.exe))

 might work. I think the substring gets the whole X:/ part of the string.

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] Centre of gravity of a mountain

2010-11-09 Thread Barry Rowlingson
On Mon, Nov 8, 2010 at 5:15 PM, Peter Langfelder
peter.langfel...@gmail.com wrote:

 If you also need the z coordinate, it simply the mean of the matrix Z.

 zCenter = mean(Z)

 How can that be right? Suppose your mountain is very flat, so that
your mountain is effectively a cube. The Z values are all the same,
and so their mean is the same. However the centre of mass is, by
symmetry, clearly at height/2.

 Similarly suppose your mountain matrix is one large cell value and
all the rest are near zero - the mean Z will be close to zero but the
centre of mass will be almost half way up the single cell value,
because all the near-zeros contribute nothing to the centre of mass
position.


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] Plotting a grid of directly specified colours

2010-11-04 Thread Barry Rowlingson
On Thu, Nov 4, 2010 at 4:00 PM, Peter Davenport pwdavenp...@gmail.com wrote:
 Dear R-help,

 Could any of you direct me to a function for plotting a grid of colours,
 directly specified by a matrix of hex colour codes?  In other words I'm
 looking for a heatmap() or image()-like function to which I can specify the
 colour of each grid location directly, rather than providing a numerical
 matrix and a 1D-colour scale (heatmap, image, levelplots,NeatMap...). I'm
 surprised I haven't found anything simple with RSiteSearch,
 help.search, net.

 I'd like to use this function to encode one variable as chroma and a
 second as luminance (hcl colour space), so that the two variables can be
 visualised in a single heatmap (the variable are fold-change and a q-value,
 a significance measure). If anyone has any thoughts/warnings to offer re
 this idea then I'd love to hear them (it must have been tried before, but
 I've not come across any examples) .

 I've kludged this kind of thing in the past. Create a matrix of
1:(nrow*ncol), and specify the col as your colour matrix.

Example:

m = matrix(c(red,green,blue,yellow,orange,black),2,3)
mc = matrix(1:(nrow(m)*ncol(m)),nrow(m),ncol(m))
image(mc,col=m)

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] Drawing circles on a chart

2010-11-03 Thread Barry Rowlingson
On Wed, Nov 3, 2010 at 2:07 AM, Santosh Srinivas
santosh.srini...@gmail.com wrote:
 Dear Group,

 Inside each cell there should be a circle (sphere preferable) with radius of
 mod(data value). The color should be either red or green depending on -ve or
 +ve and the intensity should be based on the value of the datapoint.

 Any help on how to go about this?

 If you really want a sphere then you should look at the rgl package,
which enables the drawing of 3d graphic objects with illumination.
However it does it in its own graphics window and you'll not be able
to use any of the standard R graphics functions. Otherwise you'll have
to find some way of putting a 3d sphere on  a 2d R graphics window, or
faking it with a shaded circle and some highlights. Yuck.

 Also, drawing circles (strictly, a disc) with radius proportional to
data value is usually a bad idea since we interpret areas. A circle
with twice the radius has four times the area, and so looks four times
as big. But the data is only twice as big...

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] Recoding -- test whether number begins with a certain number

2010-11-03 Thread Barry Rowlingson
On Wed, Nov 3, 2010 at 10:01 AM, Marcel Gerds marcel.ge...@gmx.de wrote:
  Dear R community,

 I have a question concerning recoding of a variable. I have a data set
 in which there is a variable devoted to the ISCO code describing the
 occupation of this certain individual
 (http://www.ilo.org/public/english/bureau/stat/isco/isco88/major.htm).
 Every type of occupation begins with a number and every number added to
 this number describes th occupation more detailed.
 Now my problem: I want to recode this variable in a way that every value
 beginning with a certain number is labeled as the respective category.
 For example, that all values of this variable beginning with a 6 is
 labeled as agri.
 My problem is that I cannot find a test which I can use for that purpose.

 I would really appreciate any help on that subject. Thank you.

 If it's a numeric variable, convert to character with 'as.character'.

 Then check the first character with substr(x,1,1). Then create a
factor and set the levels...

  z=as.integer(runif(10,0,100))
  z
 [1] 26 92 47 99  2 98 15 21 58 82
  zc=factor(substr(as.character(z),1,1))
  zc
 [1] 2 9 4 9 2 9 1 2 5 8
Levels: 1 2 4 5 8 9
  levels(zc)=c(Foo,Bar,Baz,Qux,Quux,Quuux)
  zc
 [1] Bar   Quuux Baz   Quuux Bar   Quuux Foo   Bar   Qux   Quux
Levels: Foo Bar Baz Qux Quux Quuux
  data.frame(z=z,zc=zc)
zzc
1  26   Bar
2  92 Quuux
3  47   Baz
4  99 Quuux
5   2   Bar
6  98 Quuux
7  15   Foo
8  21   Bar
9  58   Qux
10 82  Quux

 Now all the 9-somethings are Quuux, the 2's are Bar etc etc.

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] '=' vs '-'

2010-11-03 Thread Barry Rowlingson
On Wed, Nov 3, 2010 at 6:04 PM, km srikrishnamo...@gmail.com wrote:
 Hi all,

 can we use '=' instead of '-' operator for assignment in R programs?

 Yes, mostly, you can also use 'help' to ask such questions:

  help(=)

The operators ‘-’ and ‘=’ assign into the environment in which
 they are evaluated.  The operator ‘-’ can be used anywhere,
 whereas the operator ‘=’ is only allowed at the top level (e.g.,
 in the complete expression typed at the command prompt) or as one
 of the subexpressions in a braced list of expressions.

and so on...

__
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] programming questions

2010-11-03 Thread Barry Rowlingson
On Wed, Nov 3, 2010 at 6:17 PM, ivo welch ivo.we...@gmail.com wrote:
 yikes.  this is all my fault.  it was the first thing that I ever
 defined when I started using R.

   is.defined - function(name) exists(as.character(substitute(name)))

 I presume there is something much better...

 You didn't do a good job testing your is.defined :)

 Let's see what happens when you feed it 'nonexisting$garbage'. What
gets passed into 'exists'?

acs=function(name){as.character(substitute(name))}

  acs(nonexisting$garbage)
[1] $   nonexisting garbage

 - and then your exists test is doing effectively exists($) which
exists. Hence TRUE.

 What you are getting here is the expression parsed up as a function
call ($) and its args. You'll see this if you do:

  acs(fix(me))
[1] fix me

Perhaps you meant to deparse it:

  acs=function(name){as.character(deparse(substitute(name)))}
  acs(nonexisting$garbage)
 [1] nonexisting$garbage
  exists(acs(nonexisting$garbage))
 [1] FALSE

But you'd be better off testing list elements with is.null

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] Plots inside a Plot

2010-11-01 Thread Barry Rowlingson
On Mon, Nov 1, 2010 at 11:10 AM, Uwe Ligges
lig...@statistik.tu-dortmund.de wrote:
 Not in R base graphics, but you can do easily with the grid package.

 You can do anything in R base graphics! Sometimes it's been done for
you, sometimes you just have to draw the whole thing yourself using
lines().

 In this case, someone has already done it for you. subplot() in package Hmisc:

  require(Hmisc)
  plot( 11:20, sample(51:60) )
  subplot( hist(rnorm(100)), 15, 55)

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] Recursive algorithm

2010-11-01 Thread Barry Rowlingson
On Mon, Nov 1, 2010 at 10:12 AM, Megh Dal megh700...@yahoo.com wrote:
 Dear friend, I have to construct some recursive algorithm for which I used 
 some for loop like:

 res - vector(length=1)
 res[1] = 0
 for (i in 2:(1+1)) res[i] - res[i-1]*some function

 I have noticed that this is taking too much time. Is there any way to speed 
 up things?

 You can't speed ANYTHING up until you know where the time is going.
In your case, is it in some function or in R's loop. Try replacing
'some function' with a constant and see what happens. I suspect it
will be very quick.

  system.time(for (i in 2:(1+1)) res[i] - res[i-1]*1.12)
   user  system elapsed
  0.076   0.000   0.077

 yup. So it's all in 'some function'. Next question?

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] overloading the generic primitive functions + and [

2010-10-28 Thread Barry Rowlingson
On Thu, Oct 28, 2010 at 9:31 AM, Mark Heckmann mark.heckm...@gmx.de wrote:

 How can I add a new method to the generic function [ or +

 I want to create a S3 and S4 class that will use the [ and + method in a 
 different way.
 How can I overload the generic primitive [ or + so the method dispatch 
 will work correctly for my class?

 I saw an example of this in the ggplot2 package where different objects are 
 joined using the + primitive.
 Still, I could not figure out how to do that.

 Can someone give a small code example to show how that works?

 With S3 method stuff, to override + its as easy as writing Ops.{class}:

  a=hello
  b=world
  a+b
 Error in a + b : non-numeric argument to binary operator
  class(a)=ss
  class(b)=ss
  Ops.ss=function(e1,e2){paste(e1,e2)}
  a+b
 [1] hello world

 better make sure I haven't broken anything:

  c=1
  d=2
  c+d
 [1] 3   *phew*

The Ops function should really have a handler for all possible
operators (*, /, - etc) or fail with an error - see Ops.Date for
example.

With S4 classes... umm.. signatures... setMethod... setGeneric...
errr. something... representations... setClass this that... yeah.
Something like that.

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] overloading the generic primitive functions + and [

2010-10-28 Thread Barry Rowlingson
On Thu, Oct 28, 2010 at 2:12 PM, Martin Morgan mtmor...@fhcrc.org wrote:

 Not so hard, eh? Though then like your S3 implementation this makes all
 'Ops' (see ?Ops)

 Except you have to re-run the set* things every R session:

  setClass(SS, character)
  setMethod(Ops, c(SS, SS), function(e1, e2) paste(e1, e2))
  a=new(SS,hello)
  b=new(SS,world)
  a+b
 [1] hello world
  q()
 Save workspace image? [y/n/c]: y

...start R again...

[Previously saved workspace restored]

  a=new(SS,hello)
  b=new(SS,world)
  a+b
 Error in a + b : non-numeric argument to binary operator

 It seems the SS class is preserved but the method definition isn't.
Otherwise new(SS,hello) fails.

 That's one of the things that confuses me about S4 - its use of
invisible global things. ls(all.names=TRUE) shows me the bits:

  ls(all.names=TRUE)
 [1] a  .__C__SS   .requireCachedGenerics

 It seems that .__C__SS is the class definition, and the
.requireCachedGenerics seems to imply I've done something with 'Ops':

  .requireCachedGenerics
[[1]]
[1] Ops

 but doesn't actually store and restore my definition.

 A bug? I dunno. Version 2.10.1 if anyone cares. I don't. I'll just go
back to my S3 method which is just as simple and works when I restore
the .RData I saved things to. Each to their own!


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] overloading the generic primitive functions + and [

2010-10-28 Thread Barry Rowlingson
On Thu, Oct 28, 2010 at 12:14 PM, Christofer Bogaso
bogaso.christo...@gmail.com wrote:
 Dear Barry, this is really interesting. However I could not understand
 this line:

 Ops.ss=function(e1,e2){paste(e1,e2)}

 Where you have told R to behave + function differently when it faces
 ss class?
 What should be the ideal approach if I what to use * function?

 You can get the character string of the operator from '.Generic', for example:

Ops.ss=function(e1,e2){
   if(.Generic==+){
return(paste(e1,e2))
   }
   if(.Generic==*){
 return(rep(e1,e2))
   }
  stop(No definition for ,.Generic)
}

Giving:

  a*5
 [1] hello hello hello hello hello
  a+world
 [1] hello world
  a/2
 Error in Ops.ss(a, 2) : No definition for /

Note how S3 methods are dispatched only by reference to the first
argument (on the left of the operator). I think S4 beats this by
having signatures that can dispatch depending on both arguments.

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] Recovering x/y coordinates from a scatterplot image

2010-10-15 Thread Barry Rowlingson
On Fri, Oct 15, 2010 at 9:46 PM, Rob James aetiolo...@gmail.com wrote:
 Do I recall correctly that there is an R package that can take an image, and
 help one estimate the x/y coordinates?  I can't find the package, thought it
 was an R-tool, but would appreciate any leads.

 Thanks,

 I dont know an R package for this, but there are various programs to
do it, none of which I can ever remember the name once every six years
when I need it. Some searching on the internet has found this one:

http://plotdigitizer.sourceforge.net/

but doubtless there are others!

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] Create Arrays

2010-10-15 Thread Barry Rowlingson
On Fri, Oct 15, 2010 at 9:55 AM, dpender d.pen...@civil.gla.ac.uk wrote:

 Hi,

 For this example:

 O - c(0 0 0 2 0 0 2 0)

 I want to create an array every time O[i]  0.  The array should be in the
 form;

 R[j] - array(-1, dim=c(2,O[i]))

 i.e. if O[i]  0 4 times I want 4 R arrays.

 Does anyone have any suggestions?


 Suggestion number l is don't use O for objects! Far too confusing!

 Serious suggestion is that a concrete example will help. Let me try:

If:

 X = c(0,0,0,2,0,0,3,0) # I'm not using O here!

 Then

R will be a list of length 2 because there are 2 values in X bigger than 0.

R[1] will be array(-1,dim=c(2,2))   # because X[4] is 2
and
R[2] will be array(-1,dim=c(2,3))  # because X[7] is 3

 Yup?

 Okay, first get rid of the zeroes:

Xnz = X[X!=0]

 That simplifies the problem. Then use lapply to iterate over Xnz with
a function that returns the array given the value:

 lapply(Xnz,function(x){array(-1,dim=c(2,x))})
[[1]]
 [,1] [,2]
[1,]   -1   -1
[2,]   -1   -1

[[2]]
 [,1] [,2] [,3]
[1,]   -1   -1   -1
[2,]   -1   -1   -1

 2-d arrays are just matrices, so you can do it all in one line with:

lapply(X[X!=0],function(x){matrix(-1,2,x)})

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] exponentiate elements of a whole matrix

2010-10-13 Thread Barry Rowlingson
On Wed, Oct 13, 2010 at 11:51 AM, Maas James Dr (MED) j.m...@uea.ac.uk wrote:
 I've tried hard to find a way to exponentiate each element of a whole matrix 
 such that if I start with A

 A = [ 2   3
      2   4]

 I can get back B

 B = [ 7.38   20.08
      7.38   54.60]

 I've tried

 B - exp(A) but no luck.

 Your matrix notation looks unlike R. We prefer cut n paste examples
here. In which case:

  A=matrix(1:4,2,2)
  A
 [,1] [,2]
[1,]13
[2,]24
  exp(A)
 [,1] [,2]
[1,] 2.718282 20.08554
[2,] 7.389056 54.59815
  B=exp(A)
  B
 [,1] [,2]
[1,] 2.718282 20.08554
[2,] 7.389056 54.59815

so, works for me (as I expected it would).

 Either you've redefined the exp function or you've accidentally
started matlab instead.

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] Pointing to a specific place on the x-axis with an arrow

2010-10-06 Thread Barry Rowlingson
On Wed, Oct 6, 2010 at 1:45 AM, Josh B josh...@yahoo.com wrote:
 Hi all,

 I am trying to do something simple, but which is deviling me. I want to add an
 up-arrow to the x-axis, pointing to a specific location on the axis. I want 
 the
 arrow to be as large as possible.

 Here is where I'm at with my code:

 #this part if from the ?plot example:
 require(stats)
 plot(cars)
 lines(lowess(cars))
 #I am trying to use mtext to add the arrow... but I don't know how to do it:
 mtext(?, side = 1, line = 0, at = 7)
 #that question mark is a place-holder for the arrow. How do I put an up-arrow
 there instead of the question mark -- as large as possible?

 Use %up% in an expression - but I think it needs two empty {}
expressions as arguments:

mtext(expression({}%up%{}), side = 1, line = 0, at = 12)

Looks pretty good...

Barry

-- 
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman

__
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] Pointing to a specific place on the x-axis with an arrow

2010-10-06 Thread Barry Rowlingson
On Wed, Oct 6, 2010 at 11:04 AM, Michael Bedward
michael.bedw...@gmail.com wrote:
 On 6 October 2010 20:51, Ivan Calandra ivan.calan...@uni-hamburg.de wrote:

 Moreover, Josh wanted the arrow to be really big. Is it possible to make
 it bigger? I would be interested too!


 Sorry - missed that bit. You can use the cex argument of the mtext
 function to make the symbol bigger.


 And you might also need 'line=' to shift it down a bit once it starts growing.

 If all else fails, use arrows() - but that might get tricky...

  plot(1:10)
  par(xpd=NA) # dont clip to the plot
  arrows(5,0,5,1)

 You could use various other par() options to get the position of the axis...

 plot(2:20)
 par(xpd=NA)
 arrows(7,par()$usr[3]-3,7,par()$usr[3],lwd=2)

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] Pointing to a specific place on the x-axis with an arrow

2010-10-06 Thread Barry Rowlingson
On Wed, Oct 6, 2010 at 12:29 PM, Ivan Calandra
ivan.calan...@uni-hamburg.de wrote:
  Hi again,

 Just one little question. I don't understand what clipping is.
 Probably a problem with English...
 Therefore the par(xpd=NA) is not really clear for me; nor is the clip()
 function. And I don't see any difference between par(xpd=NA) and nothing.

 It's not really related to this post, let me know if I should change the
 subject.

Try this:

  par(xpd=FALSE)
  plot(1:10)
  abline(h=4)
  par(xpd=NA)
  abline(h=5)

 the first horizontal line, at y=4, should only be visible in the box
of the plot. The second line, at y=5, should go right across the
graphics window. We say the first line is 'clipped' to the box.

 so, to draw some things outside the box you have to set par(xpd=NA)
first. Its not necessary with things like mtext and axis because they
obviously are going to draw outside the box anyway. It's just for
points, lines, symbols, arrows etc.

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] is there a way to avoid traveling grid?

2010-10-05 Thread Barry Rowlingson
On Tue, Oct 5, 2010 at 3:37 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 my.data$date

I wouldn't use grid - it suggests you try abline, so something like:

  abline(v=my.data$date,lty=2)

 - to put vertical lines at your data points. For the horizontal grid
lines, we can just use the axis tick marks:

  axTicks(2)
 [1] -5  0  5 10 15 20

 thus:

  abline(h=axTicks(2), lty=2)

adjust lty and col options to suit

Barry


-- 
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman

__
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] A problem with plotting a long expression in ylab ?

2010-09-28 Thread Barry Rowlingson
On Tue, Sep 28, 2010 at 10:03 AM, Tal Galili tal.gal...@gmail.com wrote:
 Hello,

 It seems that there is a problem when plotting an expression in the ylab of
 a plot in case it is too long.

 Example:

 plot(1)
 title(ylab = test
 looong
 ) # work
 plot(1)
 title(ylab = expression(paste(test (% of 360 *degree,  # works
 plot(1)
 title(ylab = expression(paste(test looong (% of
 360 *degree,  # doesn't work

 what does 'work/doesn't work' mean?

 I see some problems with the appearance of the label, and they seem
related to the line breaks in the label. A single line label:

  plot(1)
  title(ylab=looong
cat is long)

 (where any line breaks you see are due to mail clients linebreaking)
works fine (except of course the label is truncated at the start and
end).

However if I do:

  plot(1)
  title(ylab=looong
cat is\n long)

 (with a newline char \n in there)

 I only see the last looo*oong because the first line is out of my
margin area. I can actually see the descender of the 'g', so I know
it's there.

 I think the 'doesn't work' you are having is because there's a
newline on the end of your continuation string:

  plot(1)
  title(ylab=foo
+ )  # has a newline at end
  title(ylab=foo)# doesn't

You can give more label space by using par(mar=, for example:

 par(mar=c(5,8,4,2))
 plot(1)
 title(ylab=long\ncat\nis\nlong)

 But of course you need to know how many lines your ylab will be
before you make the plot...

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] A problem with plotting a long expression in ylab ?

2010-09-28 Thread Barry Rowlingson
On Tue, Sep 28, 2010 at 10:35 AM, Tal Galili tal.gal...@gmail.com wrote:

 My point is that in regular text, ylab plots it where it then goes outside
 the borders.
 With the use of expressions - the text just doesn't show up.
 Originally I thought it was because of my miss-use of expressions, until I
 figured it was the level of cex.lab I was using.
 The problem is that when you can't see the text, you don't have a sense of
 how much to decrease the cex.lab so the text will fit.
 I hope I was now clearer.

Gotcha. Seems to only affect ylab though. Do this:

  t =  expression(paste(test
loo(% of 360 *degree,
)))
  plot(1,xlab=t,ylab=t,main=t)

then if I shrink my graphics window I can make the ylab disappear but
not the xlab or title.

 Seems to affect any rotated expressions:

 plot(1)
 text(1,1,t,srt=90)
 text(1,1,t,srt=0)
 text(1,1,t,srt=45)

 Now shrink window and watch the rotated expressions vanish! They
disappear when they start (or finish) out of the entire graphics
device, not the plot region...

 I cant find anything relating to clipping in the help, and I am on
Linux, so see if there's any news about it, try it with R-patched or
R-devel and then report a bug after having read all the other stuff
about R bug reporting!

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] Output Graphics GIF

2010-09-27 Thread Barry Rowlingson
On Mon, Sep 27, 2010 at 1:39 PM, Nilza BARROS nilzabar...@gmail.com wrote:
 Dear R users,

 How could I managed graphics in GIF  format? What I have been doing is
 graphics in *.ps or *.eps and after I convert them using CONVERT (from
 ImageMagick) but the output quality is not good.  Since these graphics will
 be use for other users they must have a better image quality.

 The png() graphics driver will produce bitmap graphics which should
convert better to a gif. PostScript is a vector format, so there may
be all sorts of things going on.

 Just feed png() with the width and height you want for your gif and
then you wont have to resize as part of the conversion process.

 Also, GIFs are pretty old-tech these days, so if you could persuade
your other users to switch to png files, its a big win.

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] Reading in .aux (ESRI raster files) into R

2010-09-25 Thread Barry Rowlingson
On Fri, Sep 24, 2010 at 3:21 PM, JoH jh...@york.ac.uk wrote:


 Error in
 readAsciiGrid(F:/GIS.LandcoverEuropeForRisk/Sept10kmmaps/Sp10KPointID.aux)
 :
  object 'cellsize' not found

 My original data in Arc GIS is have a cell size an i'mm curious as to how to
 make sure all the details are included.

 Well at this point absolutely none of the file has been included.

 I also tried to use

 Spain10km-getRasterData(F://RMap//sp10kpointid1, ,band=NULL,

 This is a different file to the one you tried above.

  Spain10km - system.file(F://RMap//sp10kpointid1, package=rgdal)

 That won't do anything useful.

 #These lines were used to then try to get it to recognise sp10kpointid1 as a
 member og the GDALReadOnly Dataset.
 x - new(GDALReadOnlyDataset, Spain10km)
 Error in .local(.Object, ...) : empty file name
 x - new(sp10kpointid1, Spain10km)


 Which is the best way to read this file into R? Why didn't it include my
 classes?

 Assuming it *is* a valid raster file, then readGDAL from the rgdal
package should handle it:

 require(rgdal)
 data = readGDAL(file.choose())

Using file.choose() here makes sure you dont muck up the path because
it will prompt you to browse for the file. readGDAL is an interface to
all the raster data types that rgdal knows about.

 If this fails, then I am wondering if the file is a valid raster
file. .aux is an odd file extension - how did you create it exactly?

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] Colorramp in Maptools, how to choose min and max values for the fg= argument

2010-09-22 Thread Barry Rowlingson
On Wed, Sep 22, 2010 at 9:56 AM, schaber kscha...@ipp.mpg.de wrote:
 Hi Jannis,

 thanks a lot for your reply. Unfortunately the solution you proposed does
 not work.
 Maybe the reason is, that plot.Map only accepts hsv colours and I do not
 know to convert the rgb colours to the right colour space.

 Isn't there a possibility to specify minimal an maximal values when using
 colorRampPalette to only choose a certain part of the colorRamp(Palette)? I
 could than define a new colorset  jet.colors2, which is picks out the
 colours between min(Vector)/10 and max(Vector)/10?

 jet.colors = colorRampPalette(c(#7F, blue, #007FFF,
                                cyan, #7FFF7F, yellow, #FF7F00,
 red, #7F))
 Intervalls - cut(as.numeric(Matrix[,nc]),n, na.rm=TRUE)  }
 fgs - jet.colors(n)[Intervalls]

 Maybe this is a bit confusing...

If you want to control precisely the mapping of numeric values to
colours, then you could try my colourschemes package from R-forge:

install.packages(colourschemes, repos=http://R-Forge.R-project.org;)

then you create a function that maps values to colours by, for
example, interpolating colours at fixed values, eg:

 rs = rampInterpolate ( limits =c(-2 , 2),
   ramp = c(red,  yellow ,  blue ))

 and then:

  rs(2)
[1] #  # gives blue
  rs(-2)
[1] #FFFF  # gives red
  rs(0.5)
[1] #BFBF40FF  # nearer yellow than blue

 so now whatever the range of your data you can just use the rs()
function to get the same colours for the same values.


  d=data.frame(x=1:10,y=1:10,V1=runif(10,0,2),V2=runif(10,-2,0),V3=runif(10,-2,2))
  plot(d$x,d$y,col=rs(d$V1))
  plot(d$x,d$y,col=rs(d$V2))
  plot(d$x,d$y,col=rs(d$V3))

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] diagnosing download.file() problems

2010-09-21 Thread Barry Rowlingson
On Tue, Sep 21, 2010 at 9:39 AM, steven mosher mosherste...@gmail.com wrote:
 I'm accessing around 95 tar files on an FTP server ranging in size between
 10 and 40MB a piece.

 while certainly can click on them and download them outside of R, I'd like
 to have my script do it.

 Retrieving the ftp directory with RCurl works fine (about 90% of the time)

 but downloading the files by looping through all the files is a random
 process.

 I may get 1-8 files download and then it throws an error

 cannot open URL 

 sometimes I only can get 1 file before this error. with tryCatch() I've been
 able to do some clean up
 after the crash, but automating this whole download process has turned into
 a bit of a circus.

 The parameters (url, destfile, mode) are all correct in the download.file
 call as the second attempt at a url will often succeed.

 Is there anyway to get a deeper look at the cause of the problem? I've tried
 closing all connections
 in between each download. any pointers would be welcomed.

Sounds to me like the FTP server is operating some kind of rate
limiting. Do you have access to the server log files, or the server
administrator, or perhaps the server's terms and conditions to see if
its so :)

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 create image like this?

2010-09-21 Thread Barry Rowlingson
On Tue, Sep 21, 2010 at 8:58 AM, zcrself zcrs...@gmail.com wrote:

 http://r.789695.n4.nabble.com/file/n2548152/25jfmyx.jpg

 HOW to create image like this?
 **tp://i55.tinypic.com/25jfmyx.jpg[/IMG]

 My first response is On an empty stomach, with a handy supply of
anti-migraine tablets.

 I don't known how to create the image above or which function can create
 this image?

 Is this a standard representation of some genetic thing? If so, then
it might be worth someone writing a function to do it, but that would
mean first defining a precise specification for the graphic. There's
nothing you can't do in R with only the lines and points functions

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] Simple question, name of the variable as string.

2010-09-17 Thread Barry Rowlingson
On Fri, Sep 17, 2010 at 7:54 AM, C.H. chainsawti...@gmail.com wrote:
 Dear R users,

 I have a very simple question and I've tried to search for the answer.
 (But failed.)

 there should be a function (func) that work like

 abc - c(1,2,3,4)
 func(abc)
 abc

 I would like to know the name of that function. Thank you very much
 for your help.

 Think: where does R do this?

 Answer: zzz = 1:10 ; plot(zzz)  # look at the y axis.

 How did it do this? Look at the code. Type 'plot' without () and
there's the code. Somewhere in there you will see where it sets the Y
axis label, or ylab.

 Then read and understand the help pages for those functions. What
happens if I do func(c(1,2,3,4))? What's the name of 'c(1,2,3,4)'?

 Its a good way to learn.

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] a reliable way to check the latest version of R on CRAN?

2010-09-17 Thread Barry Rowlingson
On Thu, Sep 16, 2010 at 5:29 PM, Yihui Xie x...@yihui.name wrote:
 Hi all,

 We know old.packages() can check for updates of add-on packages, but
 is there a way to check updates of R itself? go to R homepage is a
 way, of course, but I hope this can be done by R.

 I'm not sure about the reliable place to check; here is a simple
 example to check from one of the CRAN webpages (kind of nasty
 approach...):

 checkRVersion in gtools does it by looking for the .tar.gz releases in CRAN:

 library(gtools)
 checkRVersion()
A newer version of R is now available: 2.11.1

 and then a bit later

 checkRVersion()
The latest version of R is installed: 2.11.1

It returns the latest version and you can make it quiet for use in scripts.

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] SF-36 questionnaire scoring for R?

2010-09-13 Thread Barry Rowlingson
On Mon, Sep 13, 2010 at 11:16 AM, Dieter Menne
dieter.me...@menne-biomed.de wrote:
 Dear useRs from the physiology department,

 Does someone know of an implementation of the SF-36 questionnaire scoring in
 R? I only found SAS and STATA versions, e.g

 http://gim.med.ucla.edu/FacultyPages/Hays/util.htm


I do love SAS code for a good chuckle on a wet Monday morning...

http://gim.med.ucla.edu/FacultyPages/Hays/UTILS/SF36/sf36.sas

* SAS CODE FOR SCORING 36-ITEM HEALTH SURVEY 1.0
* WRITTEN BY RON D. HAYS, RAND, 310-393-0411 (EXT. 7581) ***;
DATA TEMP1;
 SET TEMP;
RENAME
I1=I1
I2=I2
I3=I3
I4=I4
I5=I5
I6=I6
I7=I7
I8=I8
I9=I9
I10=I10
I11=I11
I12=I12
I13=I13
I14=I14
I15=I15
I16=I16
I17=I17

[etc etc]

 The rest of it appears to be pages and pages of nested IF- statements
which could be translated into R fairly easily, but without a test set
(and currently ROFL'ing over those first 40 lines) I can't attempt.

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] Need to have more control on cat()

2010-09-13 Thread Barry Rowlingson
On Mon, Sep 13, 2010 at 11:53 AM, Christofer Bogaso
bogaso.christo...@gmail.com wrote:
 Hi all, here is my small piece of codes:

 fn1 - function(x = 4) {
    y - 0
    if(y == 0) cat(y value
                    is zero\n) # I intentionally created 2nd line here
    return(4)
 }

 If I run this function I get following

 fn1()
 y value
                    is zero
 [1] 4

 Here you see there are lot of spaces before is zero. How can I
 format cat() to force it to start from margin?

 Don't indent it? This isn't Python, you know.

  if(y==0){cat(y value
is zero\n)
}

 should work, producing

y value
is zero

 is that what you want?

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] Need to have more control on cat()

2010-09-13 Thread Barry Rowlingson
On Mon, Sep 13, 2010 at 12:11 PM, Christofer Bogaso
bogaso.christo...@gmail.com wrote:
 Thanks Barry, I agree it will work. But this approach destroys the
 indent in the program body therefore entire body of program looks
 messy, for example

 cat(Here I
        put indent)

 obviously looks better for someone who reads my code, than

 cat(Here I
 dont put indent)

 Any better approach?

 Something like:

 cat(Here I\n,
   have some indented source\n,
which doesn't output indented.,sep=)

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] difference of two RData files/environments

2010-09-10 Thread Barry Rowlingson
I just wrote up some code for differencing two .RData files or
environments (or one of each). Available from source here:

http://www.maths.lancs.ac.uk/~rowlings/R/Ediff/

In its handiest form, running:

ediff()

 will tell you the difference between your working environment and the
.RData file that it probably started from. Useful for those 'What have
I done here?' moments when you discover an R session in a long-lost
terminal window.

It can take two arguments which can be paths to files or environments.
It tells you which objects are in one or the other or both, and does
an identical() check on the ones in both.

If anyone maintains a package that this could go in, get in touch.

Barry


-- 
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman

__
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] optimized value worse than starting Value

2010-09-09 Thread Barry Rowlingson
On Wed, Sep 8, 2010 at 6:26 PM, Michael Bernsteiner
dethl...@hotmail.com wrote:
 @Barry: Yes it is the Rosenbrock Function. I'm trying out some thing I found
 here: http://math.fullerton.edu/mathews/n2003/PowellMethodMod.html

 @Ravi: Thanks for your help. I will have a closer look at the BB package. Am
 I right, that the optimx package is ofline atm? (Windows)

 It looks like the Windows build of optimx failed the R CMD check when
running the examples:

http://www.r-project.org/nosvn/R.check/r-devel-windows-ix86+x86_64/optimx-00check.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] modulo operation

2010-09-09 Thread Barry Rowlingson
2010/9/9 José M. Blanco Moreno jmbla...@ub.edu:
  Dear R-users,
 May be there is something that I am not understanding, missed or else...
 Why do these operations yield these results?
 25%/%0.2
 [1] 124
 25%%0.2
 [1] 0.2

 I would expect (although I know that what I do expect and what is really
 intended in the code may be different things)
 25/0.2
 [1] 125
 25 - floor(25/0.25)*0.25
 [1] 0

 (At least this second one is what I would expect from the code in
 arithmetic.c, lines 168 to 178)

Did you read the documentation before you read the code?

 ‘%%’ and ‘x %/% y’ can be used for non-integer ‘y’, e.g. ‘1 %/%
 0.2’, but the results are subject to rounding error and so may be
 platform-dependent.  Because the IEC 60059 representation of ‘0.2’
 is a binary fraction slightly larger than ‘0.2’, the answer to ‘1
 %/% 0.2’ should be ‘4’ but most platforms give ‘5’.

I suspect that is relevant to your interests

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] Passing aruments with source

2010-09-08 Thread Barry Rowlingson
On Wed, Sep 8, 2010 at 10:11 AM, Joel joda2...@student.uu.se wrote:

 Hi.

 Im writing a small test program just to see how passing arguments work with
 R.
 From the command line everything works as expected but from inside R using
 source(test.R) i dont know where and how to send in the arguments did try
 source(test.R --test) but it just says that it cant find or open the file.
 (without the argument part it can).

 Anyone know how to make it work?

 source() runs the file in the context of the caller, so if you have
an 'x' in the caller then the file sourced will see it. So here, where
s.R is just:

print(x)

 you can do:

 x=12
 source(s.R)
[1] 12
 x=99
 source(s.R)
[1] 99

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] Passing aruments with source

2010-09-08 Thread Barry Rowlingson
On Wed, Sep 8, 2010 at 11:29 AM, Joel joda2...@student.uu.se wrote:

 That is true but then I (or anyone else using the script) most know exactly
 what the name in the script is to be able to set it correctly and so on.
 Therefor it would be much better to be able to just send in the value and
 let the script handle the variable setting.

 But thx for the answer

 Then what you really want to do is write a _function_ that takes
arguments, and not a script. Tell your users something like:

 Do 'source(foo.R)' and then call the fnord function with your data
set: fnord(x).

Your foo.R file looks like this:

 fnord =function(x){
   print(x) # etc
 }

It's even possible to save functions to .RData files and then tell
your users to attach() them, thus not putting objects in their working
spaces.

And the next step is to write a package for your function...

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] optimized value worse than starting Value

2010-09-08 Thread Barry Rowlingson
On Wed, Sep 8, 2010 at 1:35 PM, Michael Bernsteiner
dethl...@hotmail.com wrote:

 Dear all,

 I'm optimizing a relatively simple function. Using optimize the optimized 
 parameter value is worse than the starting.
 why?

 f-function(delta,P,U){
    minimiz-P+delta*U
    x-minimiz[1]
    y-minimiz[2]
    z-100*(y-x^2)^2+(1-x)^2
    return(z)
 }

 This looks familiar. Is this some 1-d version of the Rosenbrock
Banana Function?

 http://en.wikipedia.org/wiki/Rosenbrock_function

 It's designed to be hard to find the minimum. In the real world one
would hope that things would not have such a pathological behaviour.

 Numerical optimisations are best done using as many methods as
possible - see optimise, nlm, optim, nlminb and the whole shelf of
library books devoted to 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] saving heatmaps in graphical format that can be edited in graphic editor tool

2010-09-08 Thread Barry Rowlingson
On Wed, Sep 8, 2010 at 4:32 PM, BD bhakti.dwiv...@gmail.com wrote:

 I generated a heatmap in R using the following commands:

 mydata - read.csv(file=Data.csv, header=TRUE, sep=,)
 mydata - mydata[rowSums(mydata[,-1]^2) 0, ]
 rownames(mydata)=mydata$Name
 mydata - mydata[,2:253]
 mydatamatrix - data.matrix(mydata)
 mydatascale - t(scale(t(mydatamatrix)))
 hr - hclust(as.dist(1-cor(t(mydatascale), method=pearson)),
 method=complete)
 hc - hclust(as.dist(1-cor(mydatascale, method=spearman)),
 method=complete)
 myclhr - cutree(hr, h=max(hr$height)/2); mycolhr - sample(rainbow(256));
 myclhc - cutree(hc, h=max(hc$height)/2); mycolhc - sample(rainbow(256));
 mycolhr - mycolhr[as.vector(myclhr)];
 mycolhc - mycolhc[as.vector(myclhc)];
 library(gplots)
 library(RSvgDevice)
 jpeg(Heatmap.jpg, height=6+2/3, width=6+2/3, units=in, res=1200)
 heatmap.2(mydatamatrix, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc),
 dendrogram=both,
   scale=row, col=brewer.pal(3, YlOrRd), cexRow=0.01, cexCol=0.01,
 trace=none, density.info=none,
   key=TRUE, keysize=1.5, margin=c(5,8),RowSideColor=mycolhr,
 ColSideColor=mycolhc)
 dev.off()


 I would like to save the file in a graphical format that can be edited later
 in any image editing program (like corel).  is there a way to do this in R?
 Its a lot of data I plotted on heatmap (~ 300*600). The x and y labels are
 difficult to read.  I used cexRow = 0.01 and cexCol =0.01 with 1200
 resolution to save as jpeg file.  That helped but I can still hardly figure
 out the row labels.  I want to be able to read them to interpret the results
 and also to edit them with different font/color in corel and may be add
 other things that could be relevant to my work.  So, I guess my question
 here- is there a way I can make the labels readable in R itself or can I
 generate a list of the row and col labels (in the exact order as in figure)
 in a text file separately so I know the order and can try attaching it to
 heatmap in corel draw?

 any help will be appreciated!  Thanks!

 I've been doing exactly this today.

 Use the svg() device driver to create an svg file. Then edit it with
Inkscape, and open-source graphics layout and design program. For a
demo, try:

svg(foo.svg)
plot(1:10)
dev.off()

Then open Inkscape and load foo.svg. You should be able to move all
the bits of the plot around.

 It has saved me a ton of time today, since I wanted to move a legend
on a ggplot graph to make room for another graphic. In Inkscape I can
just select the elements of the legend and drag them around.

 Inkscape is cross-platform, so works on Windows/Mac/Linux I think (am
using the Linux version).

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] queue implementation?

2010-09-07 Thread Barry Rowlingson
On Tue, Sep 7, 2010 at 8:11 AM, raje...@cse.iitm.ac.in
raje...@cse.iitm.ac.in wrote:

 Hi,

 is there a queue implementation in R?

 Tried RSiteSearch(queue)? There's one in the filehash package that
uses on-disk databases, which means it's probably fast and can handle
massive data sets.

 Conversely try this implementation which I hacked up between
breakfast and being late to work. It uses environments to handle the
dreaded R only has pass-by-value problem, and is probably okay for
smallish queues. And could be improved in many ways:

queue = function(){
  e=new.env()
  q=list()
  assign(q,q,envir=e)
  class(e)=c(queue,environment)
  e
}

push.queue=function(e,v){
  q=c(v,get(q,envir=e))
  assign(q,q,envir=e)
  v
}

pop.queue=function(e){
  q=get(q,envir=e)
  v=q[[length(q)]]
  if(length(q)==1){
  assign(q,list(),e)
}else{
  assign(q,q[1:(length(q)-1)],e)
}
  return(v)
}

print.queue=function(x,...){
  print(get(q,envir=x))
}

 And some usage:

  q=queue()
  push.queue(q,34)
 [1] 34
  push.queue(q,5.44)
 [1] 5.44
  push.queue(q,Hello)
 [1] Hello
  pop.queue(q)
 [1] 34
  pop.queue(q)
 [1] 5.44
  pop.queue(q)
 [1] Hello
  pop.queue(q)
 Error in q[[length(q)]] : attempt to select less than one element

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] queue implementation?

2010-09-07 Thread Barry Rowlingson
On Tue, Sep 7, 2010 at 3:26 PM, Spencer Graves
spencer.gra...@structuremonitoring.com wrote:
       I don't know what you mean by a queue implementation, but consider
 the following:

 A queue is a FIFO data structure - the basic operations are to add an
item to the queue and to remove an item from the queue. The item
removed is always the item that has been in the queue the longest.

 Contrast with a LIFO data structure, or stack, where the item removed
is always the most recent.

 Both of which can be implemented in R very simply with lists.

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] queue implementation?

2010-09-07 Thread Barry Rowlingson
If anyone still wants a queue implementation, I've tidied up my code
and added some docs in the file.

Info here:

http://www.maths.lancs.ac.uk/~rowlings/R/Queue/

Not a package, but a single R file with a few functions in it. If
anyone wants to put it in a package, go ahead.

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] Aggregate certain rows in a matrix

2010-09-06 Thread Barry Rowlingson
On Mon, Sep 6, 2010 at 3:29 PM, Kennedy henrik.aldb...@gmail.com wrote:

 I want to reduce the matrix according to the following: If the values of the
 two first columns are the same in two or more rows the values in the third
 column of the corresponding rows should be added and only one of the rows
 should be keept. Hence the matrix M above should look like this

  1 2 6
  1 3 4
  2 4 11
  3 4 7
  3 5 17
  3 6 10

Use library(plyr), convert to data frame, do ddply, convert back to
matrix if you want. I'm surprised mmply doesn't do it, but I dont
think it does:

  Md=data.frame(M)
  ddply(Md,c(1,2),function(r){sum(r[,3])})
  X1 X2 V1
1  1  2  6
2  1  3  4
3  2  4 11
4  3  4  7
5  3  5 17
6  3  6 10

plyr is on CRAN and that's the third time today I've told someone to use 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] How to generate integers from uniform distribution with fixed mean

2010-09-04 Thread Barry Rowlingson
On Sat, Sep 4, 2010 at 8:07 AM, Yi liuyi.fe...@gmail.com wrote:
 Sorry I forgot to talk about the range.

 But as an example, range (17,23) works.

 In your codes, mean is not exactly 20 and the samples are not integer.

 The samples *are* integers. sample(17:23,1,TRUE) returns integers.

 However, what I want is integers with mean 20 exactly.

 Any tips?


 Well, something will have to go. You can't have a random uniform
sample of integers within a given range and have an exact mean every
time.

 Suppose your range was -1 to 1, so possible values -1,0,1, and you
want integer mean 0. The only way to do that is to have equal numbers
of -1s and +1s in your sample, and the number of zeros is irrelevant -
you could have 5000 zeroes and the mean would still be 0 if you had 25
-1s and 25 +1s - thats clearly not a uniform distribution, and you'll
have to impose certain conditions if that's what you want.

 By extension, as long as you have an odd number of integers in your
sample and you want the mean to be the median value (so in the 17:23
example, mean of 20) it is sufficient to generate the same number of
17s as 23s, the same number of 18s as 22s, the same number of 19s as
21s, and as many 20s as you like.

 Not exactly sure of the maths for non-median means, you'd have to
pick fewer values on one side to cancel out the extra weight on the
other. But given that this 'distribution' is going to be weird in many
ways, perhaps you should answer the question: Why?

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] return from .Call()

2010-09-04 Thread Barry Rowlingson
On Sat, Sep 4, 2010 at 10:17 AM, raje...@cse.iitm.ac.in
raje...@cse.iitm.ac.in wrote:

 Hi,

 I have a .Call in my R function in a loop that repeats a certain number of 
 times. Each time, the .Call returns a list. So, when I say something like,

 y-func()

 would y be a list of lists?(as many as the number of loops?)

No, it'll be the last thing evaluated or the result of a return()
call. Why haven't you tried this?

Try a simple example:

func = function(){
  for(i in 1:10){
 z=list(a=1,b=2)
   }
}

and see what comes back. My suspicion is its not going to be a list of lists.

 If you want a list of lists then you'll have to put the list together
yourself from the returns of the .Call, something like (not tested,
but looks okay):

 func = function(){
   ret=list()
   for(i in 1:10){
 ret[[i]]=list(i,i*2,i*3)
}
return(ret)
  }

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 generate integers from uniform distribution with fixed mean

2010-09-02 Thread Barry Rowlingson
On Thu, Sep 2, 2010 at 7:17 AM, Yi liuyi.fe...@gmail.com wrote:
 Hi, folks,

 runif (n,min,max) is the typical code for generate R.V from uniform dist.

 But what if we need to fix the mean as 20, and we want the values to be
 integers only?

 It's not clear what you want. Uniformly random integers with expected
mean 20 - but what range? Any range centred on 20 will work, for
example you could use sample() with replacement. To see the
distribution, use sample()

 table(sample(17:23,1,TRUE))

 which gives a uniform distribution of integers from 17 to 23, so the
mean is 20.0057 for 1 samples.

 Is that what you want?

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] Remove Loading required package message

2010-08-31 Thread Barry Rowlingson
On Tue, Aug 31, 2010 at 5:21 PM, Allan Engelhardt all...@cybaea.com wrote:


 On 27/08/10 10:19, Barry Rowlingson wrote:

 On Fri, Aug 27, 2010 at 9:09 AM, Sébastien Moretti
 sebastien.more...@unil.ch  wrote:
   [...]
  require it quietly:



 require(sp,quietly=TRUE)


 Doesn't work for me:

 require(Matrix, quietly=TRUE)
 Loading required package: lattice

 Attaching package: 'Matrix'

 The following object(s) are masked from 'package:base':

    det


Actually it is suppressing the 'Loading required package: Matrix'
message, but not the message from loading 'lattice' the dependency -
perhaps the quietly= option should be passed down to required
packages?

 The other bit, Attaching package: Matrix etc only comes up because
of the masking of 'det'. If you also try warn.conflicts=FALSE then
that should stop conflict messages from Matrix, but not from required
packages - possibly because require calls library to do the load, and
that doesn't have 'quietly'... The code is slightly confusing me and
someone else probably knows more. But no, quietly=TRUE is working 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] Include local files when running R remotely

2010-08-30 Thread Barry Rowlingson
On Mon, Aug 30, 2010 at 5:29 PM, Erik Shilts erik.shi...@opower.com wrote:
 I run R on a remote UNIX server where the data are stored that I ssh into
 through Emacs, while I store my R scripts on local Windows network drives.
 So far this arrangement hasn't been a problem, though now I'd like to use
 source() or a similar function to include other R scripts to get a better
 handle on my process management. Is this possible when running R remotely?
 When I try to use source() it tells me that the file doesn't exist since
 it's looking for it on the UNIX servers.

 Any help is much appreciated. Thanks!

 Sounds like a file sharing problem rather than an R problem - ideas
that pop into my head include:

 * mounting the Windows drives on the Unix box - this requires sharing
them out in Windows, and being able to run smbmount on the unix box.

 * get rsync for Windows (maybe install cygwin and get a bunch of
useful Unixy tools for Windows) and use that to efficiently copy from
one machine to the other. But that relies on you remembering to sync
and making sure you dont sync the wrong way. Because then you'll be
sunk.

 * there may be implementations of NFS on Windows, which mean you
could NFS-mount the Unix drives on your Windows box - but I've always
found those things to be a bit flaky.

 The two options involving mounting will require cooperation of your
superuser...

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] Saving plot to tiff, with high resolution for publication ?

2010-08-29 Thread Barry Rowlingson
On Sun, Aug 29, 2010 at 5:46 PM, Tal Galili tal.gal...@gmail.com wrote:
 Hello all.

 A Journal we are sending an article to is asking for the following:

  To ensure the best reproduction quality of your figures we would appreciate
 high resolution files. All figures should preferably be in TIFF or EPS
 format... and should have the following resolution: Graph: 800 - 1200 DPI

 Photo: 400 - 800 DPI

 Color (only CMYK): 300 - 400 DPI (DPI = dots per inch)

 Since I am sending a graph, I am trying to save it using tiff.

 Firstly, EPS is a vector format so DPI doesn't make any sense (except
for embedding raster image data within it).

 Secondly, how do you know many dots (pixels) to make your image if
you don't know how big in inches your image is going to be?

 Thirdly, if its a graph, it's probably best saved as an EPS to
preserve the inherent vector nature of a plot.

 Fourthly, I should have answered this on stackoverflow.org in order
to increase my reputation points :) Or maybe decrease them :)

 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   >