Re: [R] Help with Dates

2007-07-23 Thread Hans-Peter
 I am taking an excel dataset and reading it into R using read.table.
 (actually I am dumping the data into a .txt file first and then reading data
 in to R).

If you are on *windows* you could also try my xlsReadWrite package
which contains some datetime functions. Exceldates (e.g. formatted as
dd-mmm-yy) can be read as COleDateTime (floating point) values or as
character strings.  The first one is preferable imo as it avoids a
typecast and it is the type commonly used in OLE automation.

 But how can I subset for multiple periods e.g 00- 05?

Floating point numbers dates can be converted to year-strings with
dateTimeToStr( value, yy ) and then subset as shown in a previous
post. The (paid) pro version contains many more date functions, e.g.
yearOf. Details see
http://treetron.googlepages.com/xls.oledatetimeex.html.

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] Send SMS out of R?

2007-07-15 Thread Hans-Peter
 Now I want to send an SMS out of R! Any idea how it could work? Could I send
 an eMail to a mobile phone number?

There are Email to SMS services you can use. Google gives plenty of
them (also free ones (which I wouldn't use myself...)).

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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 Excel (.xls) files on non-Windows OSs using Perl

2007-07-09 Thread Hans-Peter
Hi,

2007/7/8, Marc Schwartz [EMAIL PROTECTED]:
 [snip]
 There exists the xlsReadWrite package on CRAN by Hans-Peter Suter, which
 is restricted to Windows, since it utilizes the non-FOSS MS Office API
 to write the Excel formats.

The non-FOSS API is not the problem(#) but its implementation is:

The 3rd party library I use is written in Pascal and supports Delphi
and Kylix. Kylix would allow to port the package to Linux but as Kylix
has unfortunately been abandoned by CodeGear (Borland) I am not
ready/interested to spend my time on this dead road. Though it
probably could be done quickly.

A much more interesting way is to port the package using FreePascal.
-- I plan to do this since long but...
-- Maybe someone fluent on Linux and FreePascal could have a look at
the pascal header files (treetron.googlepages.com) and make the demos
run on Linux..., that would be great and speed up an eventual
xlsReadWrite port!

-- 
Regards,
Hans-Peter

(#) at least for people who are not in principle opposed to run a
package which contains a non-FOSS code part.

__
R-help@stat.math.ethz.ch 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 xlsReadWrite package

2007-06-17 Thread Hans-Peter
Hi,

2007/6/11, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 I have installed R 2.4.0 in my pc. I have a file xls entitled dali following 
 this directory:c://programfiles//R 2.4.0. Recently I have installed 
 xlsreadwrite 1.3.2. but , when I wrote the following lines:
 library(xlsReadWrite)
 read.xls( file, colNames = TRUE, sheet = 1, type = data.frame,  from = 1, 
 colClasses = NA )
 I obtained from R console the following messages:
 Error in library(xlsReadWrite)
 impossible to find the functionread.xls.

xlsReadWrite 1.3.2 and 1.3.3 won't work with R2.4.0. They need R2.4.1 at least.
Unfortunately xlsReadWrite 1.3.2 didn't check this requirement
properly, but v1.3.3 does. IIRC (I am not in my office right now) the
reason for it is the argument: stringsAsFactors =
default.stringsAsFactors().

You have 2 options:
- use R version 2.4.1 or 2.5.0.
- download the package in source form, remove the
default.stringsAsFactors() part and build the binary package from this
modified source.

BTW, according to the posting guide you should have contacted the
maintainer (me) first before posting to R-help. But I didn't get an
email from you...

Hope this helps and best regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] Unit Testing Frameworks: summary and brief discussion

2007-05-09 Thread Hans-Peter
 - My code gives error and warning messages in some situations. I want to
 test that the errors and warnings work, but these flags are the correct
 response to the test. In fact, it is an error if I don't get the flag.
 How easy is it to set up automatic tests to check warning and error
 messages work?

Maybe like this:

### for errors:
res1fkt - function() xls.info( exc )
res1 - try( res1fkt(), silent = TRUE )
if (class( res1 ) != try-error) stop( xls.info, data not equal )
cat( REQUIRED (EXPECTED) error message: , res1  )

### for warnings:
tryCatch( res1 - encodeDateTime( yd, md, dd, hd, mind, secd, msd ),
warning = function(x) cat(REQUIRED (EXPECTED) warning
message:\n, x$message, \n ) )
  # have to resubmit the command as I didn't find a way to execute the command
  # (assignement) and catch the warning message (but suppress the warning)
suppressWarnings( res1 - encodeDateTime( yd, md, dd, hd, mind, secd, msd ) )
if (!all( res1 == ddate )) stop( encode/decode , data not equal )


-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] Update of xlsReadWrite package

2007-04-27 Thread Hans-Peter
The (*windows only*) xlsReadWrite package has been updated and the new
version is available on CRAN.

xlsReadWrite natively reads and writes Excel files (v97 - 2003).


o Changes from v1.1.1 to v1.3.3 (versions between never really published)

  - ROWNAMES-support also for matrices (not only for data.frame)
  - explicit rowNames argument in interface.
(stimulated by email Adrian Dusa)

  - support for DATE and TIME values: Excel date and/or time values can
be retrieved as ISO-8601 format string.
- Either explicitly with the colClasses entries:
  - isodate as -MM-DD
  - isotime as hh:mm:ss
  - isodatetimeas -MM-DD hh:mm:ss
- Or for data.frame an eventual date/time type can be automatically
  determined from the value(s) of the first Excel row (determined from
  the cell formatting as there are no real date types in Excel)

   - There are four DATE CONVERSION ROUTINES (taken from pro) which enable
 you to work with Excel date/times values:
 - dateTimeToStr converts an ole datetime value to a string
 - strToDateTime vice versa (depends on local settings)
 - dateTimeToIsoStr  }
 - isoStrToDateTime  } independent of local settings
(date/time support stimulated by an email of Gabor Grothendiek)

  - new argument stringsAsFactors = default.stringsAsFactors()
(proposed by Peter Cock)
Remark: this is a *potentially code breaking change*.
Until now strings have been retrieved as characters.

  - new argument checkNames = TRUE
(proposed by Peter Cock)

  - colClasses entries modified:
- numeric and factor added,
- rowname removed (is now a proper argument)
- scalar values will be recycled (proposed by David Kinniburgh)
  - if explicit colClasses have not been given, the colClasses will
be determined from the first 16 Excelrows)
(stimulated by email David Kinniburgh)

  - empty cells for double columns come now as NA (before it was 0)

  - factors now handled in the Delphi (calls R function as.factor)
  - matrix output-type otFactor removed (not used)
  - fixed NA factors bug (thanks to Mark W. Kimpel)
  - range checks disabled again (flexcel needs this)
  - some other small fixes


o Function declarations as per v1.3.2
  - read.xls( file,
  colNames = TRUE,
  sheet = 1,
  type = data.frame,
  from = 1,
  rowNames = NA, colClasses = NA, checkNames = TRUE,
  dateTimeAs = numeric,
  stringsAsFactors = default.stringsAsFactors() )

  - write.xls( x, file,
   colNames = TRUE,
   sheet = 1,
   from = 1,
   rowNames = NA )

  - dateTimeToStr( odate, format =  )
  - strToDateTime( sdate )
  - dateTimeToIsoStr( odate, isoformat = -MM-DD hh:mm:ss )
  - isoStrToDateTime( sdate )


o Download

  - CRAN (v1.3.2; from within RGui) or
  - http://treetron.googlepages.com/ (v1.3.3)
- direct link to package:
http://treetron.googlepages.com/xlsReadWrite_1.3.3.zip
- direct link to test-/demoscripts:
http://treetron.googlepages.com/xlsReadWrite_TestData_1.3.3.zip

  - the testscript is used for our internal unittests. It will show
you many examples of how to use the package.


Comments and suggestions are welcome.
Hope you enjoy using xlsReadWrite!


-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] [ANN:] new package xlsReadWrite*Pro*: announce + update.

2007-04-27 Thread Hans-Peter
, weekOfTheMonth, dayOfTheWeek, hourOfTheDay,
minuteOfTheDay, secondOfTheDay, milliSecondOfTheDay, yearsBetween,
monthsBetween, weeksBetween, daysBetween, yearSpan, monthSpan,
weekSpan, daySpan, hourSpan, minuteSpan, secondSpan, milliSecondSpan,
incYear, incMonth, incWeek, recodeYear, recodeMonth, recodeDay,
recodeHour, recodeMinute, recodeSecond, recodeMilliSecond,
sameDateTime, sameDate, sameTime, dateTimeToJulianDate,
julianDateToDateTime, dateTimeToModifiedJulianDate,
modifiedJulianDateToDateTime

--
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] importing excel-file

2007-04-20 Thread Hans-Peter
Hi Alberto,


 I can't call read.xls while Excel is opening the xls file.
 R crashes and must be aborted.

Could not reproduce here (Win2000, Excel 2003, R 2.4.1 and
2.5.0.alpha). Who knows... but I cannot think of anything that could
cause such a problem: xlsReadWrite works on the plain file (Excel is
not even needed), doesn't lock the file and, if there were problems,
handles eventual exceptions before leaving the DLL. If you have a
reproducible test case I would be very interested in it.

[Unrelated with this, I found that read.xls doesn't work any longer
with R versions = 2.3.1. Reason: I used 'default.stringsAsFactors()'
in the stringsAsFactor argument.  = DESCRIPTION-Depends field updated
in v1.3.3].


 I have a spreadsheet where in the first line A1..ZZ1 there are the
 names of some products. However, A1 is empty,
   
This is the problem. With rowNames=NA (the default) the first Excel
column will be *considered* (under certain conditions) to contain the
*rownames*. The first element beeing empty is such a condition. It's
in the help, but not 100 % clear and some conditions have been
missing. [= help text updated in v1.3.3]

'rowNames = FALSE' prevents the auto-row-consideration.


 I will lose the first column: test1[1,1] will be B2.

The first column has been taken for the rownames.


 If I do:
 test3 - read.xls(filename, sheet = sheet name, colNames = FALSE)
 I will get A8..A311 (but these are not numbers, and I can't convert them to 
 the dates.

If you have a title row in Excel, you should skip this row (i.e. in
your case use 'from=2') because otherwise the columns will be
recognized as character columns which is not what you want.


 I get A8..A311 as something remotely similar to dates (I can even
 display them as dates:
 as.POSIXlt(1899-12-30, GMT) + test4[8:17, 1] * 86400

If you set dateTimeAs=isodatetime or use the colClasses entries
isodate, isotime or isodatetime you can get them directly as
character date strings.

Another option is to retrieve the numbers and use the new conversion
functions dateTimeToStr or dateTimeToIsoStr.


 will return a vector of dates!), but then I will lose the meaning
 of the columns, because test4[,1] is no longer the list of the
 product names.
 So it seems that none of the four possibilities is entirely satisfactory.

Well, supreme satisfaction can definitely only be gained with the pro
version...

...but the following should make you happy too:

test9 - read.xls( filename, sheet = sheet name, rowNames = FALSE,
dateTimeAs = isodatetime )

;-)


-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] importing excel-file

2007-04-20 Thread Hans-Peter
 This is Windows XP, Excel 2003, R 2.4.1.
 Maybe the problem is with Windows XP. I know that it locks some
 files, even when I open for reading. For example, if I open 'test.xls'
 file, then I can't issue the DOS command 'copy test.xls new_test.xls'.

Thanks for your information. Will test sometimes later.


 I added colClasses = double, and now it works - but I lose all
 strings, that become NAs (they don't matter - maybe if they matter,
 I just have to call read.xls twice). Without colClasses = double,
 the numbers become meaningless stuff.

If a scalar colClasses argument is given, it will be recycled for all
columns (see help). Thus a character value will be coerced to double
and becomes NA.

I don't understand though what is the matter with teh numbers becoming
meaningless stuff. With:

test9 - read.xls( filename, sheet = sheet name, rowNames = FALSE )
 # (dateTimeAs argument default, i.e. numeric)
dateTimeToStr( test9$NumberColumn )

you should get valid numbers (and dates). With
dateTimeAs=isodatetime there could be localization issues (i.e. the
date time formatting of the cell is not recognized). But I'd need a
test file to say for sure.


-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] importing excel-file

2007-04-19 Thread Hans-Peter
2007/4/18, Alberto Monteiro [EMAIL PROTECTED]:
 Method 2:
 This method uses library xlsReadWrite. You must know the index
 of the spreadsheet that you want to load:
 plan6 - read.xls(filename, sheet = 6, colClasses=double)

it works with the sheet name too! You can write:
plan6 - read.xls(filename, sheet = sheet name, colClasses=double)

 This works in most cases.

Huu? (the package is supposed to work in *all* cases...!). Do you use
the newest version (v1.3.1 or v1.3.2)? If there are any bugs/issues,
please report them to me and they - most likely - will get fixed.

-- 
Regards,
Hans-Peter
(author of xlsReadWrite)

__
R-help@stat.math.ethz.ch 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] matrix building with two variables

2007-04-19 Thread Hans-Peter
2007/4/19, Schmitt, Corinna [EMAIL PROTECTED]:
 Thanks.

 I did read everything I could but could not understand everything. Hopefully 
 with more programming practice it will become more less.


Here is a great book:

Uwe Ligges: Programmieren mit R.

worth every Rappen

:-)

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] importing excel-file

2007-04-18 Thread Hans-Peter
2007/4/18, Schmitt, Corinna [EMAIL PROTECTED]:
 It is a quite stupid question but please help me. I am very confuced. I
 am able to import normal txt ant mat-files to R but unable to import
 .xls-file

Searching for Excel on e.g. http://www.r-project.org/search.html,
http://tolstoy.newcastle.edu.au/R/about.html or
http://wiki.r-project.org/rwiki/doku.php gives:
- RODBC package
- xlsReadWrite package
- gdata package
- rexcelpoi package
- ActiveX (RDCOMClient package, search for examples in the mailling list)
- read.table command to read .csv files

I'd take xlsReadWrite (but I am biased), RODBC is also good. ActiveX
if you have lower level know how. read.table if working with .csv
files is ok.

 I do not understand the online help. Can please anyone send me the
 corresponding command lines?

library(xlsReadWrite)
dat - read.xls( filename )

details in ?read.xls

The .xls-file is attached.

binary files will be dropped from the list

In my file we
 use commas for the decimal format (example: 0,712), changes might be
 needed.

Don't know if this is relevant. Sorry.

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] Updating a worksheet in Excel file using RODBC

2007-03-23 Thread Hans-Peter
Hi,

2007/3/23, Moshe Olshansky [EMAIL PROTECTED]:
 Hello!

I have no problem reading Excel files (each worksheet in the file is
a table which can be read - at least in my case).
What I would like to do is to read such a table, change it (just the
contents, not the format) and write it back, and this I can not do.
I am getting the following error messages (3 slightly different
attempts):

 [snip]

As another option (if you work with Windows) you can check my
xlsReadWrite package (- CRAN).

It should work very well in your case (it's not suited if you want to
use SQL (join) statements, but for plain data reading/writing it is
nice).

For both versions (free/pro) updates are pending. They should be
released by end of next week (but no guarantees).

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] BETA testers for xlsReadWrite? (natively read/write Excelfiles)

2007-03-19 Thread Hans-Peter
Dear UseRs,

I have an update ready for the xlsReadWrite package. It runs my unit
tests just fine but there are quite a lot of changes and it would be
good if some other people could try it out before it will be submited
to CRAN. I won't have more time this week, but I hope to publish
xlsReadWrite at the end of next week and I will incorporate eventual
bugreports and/or (minor) suggestions which I learn of.

The most important new features are + possibility to read/write
dates/times + rownames for matrices + checknames (colnames) + better
factor support + 'stringsAsFactors' and 'rownames' argument. I also
added 4 general purpose datetime functions to convert excel dates
from/to strings.

Download:
- zip: http://treetron.googlepages.com/BETAxlsReadWrite_1.2.1.zip
- source: http://treetron.googlepages.com/BETAxlsReadWrite_1.2.1.tar.gz
- testdata: http://treetron.googlepages.com/BETAxlsReadWrite_TestData_1.2.1.zip

Some of you may be aware that this package is made with Delphi and
contains Object Pascal code. It doesn't matter normally but now I
mention it, because this evening I got the brand new Delphi 2007 and
xlsReadWrite was the thing used to try out this (very good) new
version...

-- 
Regards,
Hans-Peter


PS: @David: no more range_error violations.

__
R-help@stat.math.ethz.ch 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] BETA testers for xlsReadWrite? (natively read/write Excelfiles)

2007-03-19 Thread Hans-Peter
sorry I forgot:

 Download:
 - zip: http://treetron.googlepages.com/BETAxlsReadWrite_1.2.1.zip

Please remove the BETA prefix from the filename (otherwise it cannot
be installed).

Hans-Peter

__
R-help@stat.math.ethz.ch 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 extension

2006-12-20 Thread Hans-Peter
2006/12/20, michele de meo [EMAIL PROTECTED]:
 I'd like to develop a simple library in R in which to save my
 particular functions.

 I know that it's possible to save functions in the workspace, but I
 need this functions in a library.

- As an option you could also save the function in a textfile and
source it in the beginning of an R session (- e.g. in the
profile.site file in RHOME\etc

- Otherwise you will have to re-read about building packages. Packages
are great (e.g. for consistent documentation, tests, ...) but have the
disadvantage that they are more complicated and less flexible than
just sourcing code. If your code changes (often) I'd recommend to
automate the whole package-building-process.

If you are on windows, maybe the following which I had laying around will help:


Download and Install

- Perl: http://activestate.com/store/activeperl/
- Rtools: http://www.murdoch-sutherland.com/Rtools/tools.zip
  (extract in a directory like e.g. programme\R\Rtools)
- MS HTML Help Workshop:
http://msdn.microsoft.com/library/en-us/htmlhelp/html/hwmicrosofthtmlhelpdownloads.asp
- TeX:  download current version at: http://www.miktex.org/
at the moment:
http://prdownloads.sourceforge.net/miktex/basic-miktex-2.5.2471.exe?download

Adjust Windows environmental variables (~System-Erweitert-Umgebungsvariablen)

- PATH: In this variable the paths to the installed programs above
have to be. With the installation this has normally be done
automatically. For the Rtools you have to do it yourself: add the path
to the tools bin folder. Take care not to change the other paths. And
check if the path for the programs above are correct/included. A GOOD
IDEA is to copy the whole path in a text editor, modify and copy it
back.
- If I remember correctly the TeX program needs a nonstandard temp
directory variable: TMPDIR. Add this variable to the system
variables, choose the same value as for the other temp variable (TEMP,
TMP, ...).

Optional tools
-
- yap (to read *.dvi files, maybe this is already included in the
miktex TeX download)

Additonal info
-
[1] http://statmath.wu-wien.ac.at/staff/dekic/Rwin/
[2] http://statmath.wu-wien.ac.at/staff/dekic/Rwin/LinkedDocuments/Anleitung.pdf
[3] http://www.murdoch-sutherland.com/Rtools/


Use package.skeleton to make a prototype (this is VERY useful). To
build the packages you can use bat (batch) files, e.g. something like:
set rver=2.3.1
set rcmd=C:\Programme\R\R-%rver%\bin\Rcmd.exe
%rcmd% check %prj%
%rcmd% INSTALL --docs=txt,html,example,chm --library=../../TempInstall %prj%

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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_Code

2006-12-14 Thread Hans-Peter
2006/12/13, Duncan Murdoch [EMAIL PROTECTED]:
[snipped]

Good description. Thank you!!

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] Calling R functions in Delphi

2006-12-05 Thread Hans-Peter
2006/12/5, Rainer M Krug [EMAIL PROTECTED]:
 There was a translation of the header files from C to Delphi, so that
 you could used R directly without using DCom - Hans-Peter Suter
 translated / made them.

Thanks for mentioning. You can download these files any time from:
  - http://treetron.googlepages.com/  (select delphi interface units)

BUT notice, that they will only enable you to write *packages* which
contain Delphi code and not to link/embed R directly from Delphi. IMO
you should use RCom as mentioned above.

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] delete content of directory - unlink doesn't work as expected

2006-11-28 Thread Hans-Peter
Hi,

I try to delete the files in a directory. While the command

invisible(lapply( list.files( DeleteThis ), function(x)
file.remove(paste(DeleteThis, x, sep=/ )) ))

works, I keep thinking that there should be a more direct command.

unlink looks like a good candidate but whith this I only arrive to
either delete the whole directory or nothing happens at all. Code:

file.exists( DeleteThis )# TRUE: folder is here

(unlink( DeleteThis/*.* )) # 0, content doesn't get deleted
(unlink( DeleteThis/* ))   # do.
(unlink( DeleteThis/*.*, TRUE ))  # do.
(unlink( DeleteThis/*, TRUE ))# do.

unlink( DeleteThis, TRUE )  # whole folder will be deleted

According to the help placeholders are allowed so I don't see where is an error.

Thanks for your help!

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] delete content of directory - unlink doesn't work as expected

2006-11-28 Thread Hans-Peter
2006/11/28, Gabor Grothendieck [EMAIL PROTECTED]:

 file.remove(file.path(myDir, list.files(myDir)))

Great, thanks a lot.

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] delete content of directory - unlink doesn't work as expected

2006-11-28 Thread Hans-Peter
  invisible(lapply( list.files( DeleteThis ), function(x)
  file.remove(paste(DeleteThis, x, sep=/ )) ))

 Oh, dear!  file.path() exists for a reason, and file.remove is
 vectorized.  Try
 file.remove(dir(DeleteThis, full.names=TRUE))

argh, very embarassing to have asked this...

;-(

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] data in form of a date

2006-11-23 Thread Hans-Peter
Hi,

2006/11/22, James J. Roper [EMAIL PROTECTED]:
 I often use dates and times in analyses.  I just can't figure out how to
 format my date or time column in R.  So, apparently R sees the date as
 something other than date (character).  Let's say I am opening a CSV
 file, one of the columns of which is a date or time.  How do I specify
 that when opening the file?

In the xlsReadWrite*Pro* version I have implemented an oleDateTime
(and oleDate and oleTime) class which works quite nicely with Excel
dates
- info: http://treetron.googlepages.com/
- download zip: http://treetron.googlepages.com/xlsReadWritePro_1.0.5.zip

If you are on windows you might want to try that out. The
xlsReadWritePro version is not free like xlsReadWrite, sorry. But as
you work in ecology I'll send you a free key (if non-free packages are
in principle acceptable for you). Just contact me off list.

In the next version of the free xlsReadWrite package I have at least
implemented that dates will be retrieved as ISO formated date/time
strings. The format is fixed and you are able to convert this to R
date related classes (e.g. chron, date, POSIXt/ct/lt, fCalendar). -
The new xlsReadWrite is finished but not yet uploaded, I just uploaded
it unofficially:
- bin zip: http://treetron.googlepages.com/xlsReadWrite_1.2.0.zip
- source: http://treetron.googlepages.com/xlsReadWrite_1.2.0.tar.gz

It should be ok, i.e. runs my internal tests, but I want to add some
more tests before official release. New is also that you can specify
rowNames for matrices (and not only data.frame).

Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] Env: Re: query in R

2006-11-09 Thread Hans-Peter
2006/11/9, Ricardo Rodríguez [EMAIL PROTECTED]:

 Thus, sticking with Excel, there are two options as far as I know: RODBC or 
 the read.xls function included with a number of packages. read.xls 
 temporarely transform your xls files into csv ones. I've never successfully 
 imported data by using this path as I getting a number of errors likely 
 related to my Perl installation (the function uses Perl for the 
 transformation to csv). RODBC is out of the question here as far as we mostly 
 use Mac and Linux boxes. Even though there is ODBC for Mac OS X, we do prefer 
 to avoid it and to natively get the data from MySQL by using RMySQL.

For Linux/Mac I cannot help*, but on the windows platform I'd like to
mention my xlsReadWrite package which is a good thing if you need/want
to work with Excelfiles.

It contains the two commands: read.xls and write.xls which work
with data.frames and/or matrices. The package can be downloaded from
cran but there is an update due soon (with explicit support for
rownames and datetime handling (as ISO strings)).

-- 
Regards,
Hans-Peter

*at least right now

__
R-help@stat.math.ethz.ch 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] can Rgui.exe be launched with a script as an argument?

2006-11-08 Thread Hans-Peter
2006/11/8, Lanre Okusanya [EMAIL PROTECTED]:
 I assume this is windoze. Have you considered using the Rterm? You can

windows...   afaic

try with R.exe or, as said and imho better, Rterm.exe. Examples

testR.bat:
 set cmd=C:\Programme\R\R-2.3.1\Bin\R.exe
 call %cmd% CMD BATCH --slave --vanilla --args sayHello.R rout.txt

testT.bat:
 set cmd=C:\Programme\R\R-2.3.1\Bin\Rterm.exe
 call %cmd% --vanilla  sayHello.R  rtermout.txt

sayHello.R:
 cat( hello chappi\n )
 q()


--
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] for importing data

2006-10-30 Thread Hans-Peter
Hi,

 *I had an Excel file,  then I turned it into a tab-delimited file, as
 ...
 lahore-read.delim(lahore.txt)

I suppose you are on windows, hence you can use the package
xlsReadWrite to read the Excelfile directly. It's on the CRAN and you
can download it from the RGui under the menu: Packages -  Install
package(s)... (select a mirror, download).

Example: lahore - read.xls( lahore.xls )

Gives back the data from the first sheet as a data.frame and assumes
that there is a header row. Without header row set the colNames
argument to FALSE.

This is a user contributed package and doesn't belong to the core R
environment, hence you shouldn't post in this group if need help with
it (contact me or much better go to:
http://groups.google.ch/group/supportR). xlsReadWrite is a bit
non-standard and currently non-portable. So maybe not appropriate for
a novice. On the other hand it is easy to use and no need for csv
detours to get your data...

 Error in file(file, r) : unable to open connection
 In addition: Warning message:
 cannot open file 'lahore.txt', reason 'No such file or directory'

Already answered: ?getwd  ?setwd

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] xlsReadWritePro trial available

2006-10-28 Thread Hans-Peter
Hi,

I just finished xlsReadWritePro, a package that is - like the free
xlsReadWrite - capable to read and write native Excel files.

The Pro version is a shareware package and adds features such as: •
Sheet handling (select/insert/copy/delete/ren.) • Select regions
(columns, rows, cells or area) • Append data (several possibilities) •
Work with multiple files at the same time • Inside information of an
Excelfile • oledatetime classes (Beta) with many additional functions
• the pro version is formally supported.

Please have a look for yourself. I have put the documentation online:
http://treetron.googlepages.com/00Index.html,
http://treetron.googlepages.com/read.xls.html,
http://treetron.googlepages.com/xls.sheet.html, and more...

You can download a free trial (of 30 days) here:
http://treetron.googlepages.com/ or direct:
http://treetron.googlepages.com/xlsReadWritePro_1.0.1.zip and
http://treetron.googlepages.com/xlsReadWritePro_TestData_1.0.1.zip.

Currently only the trial is available, and it is not yet possible to
buy something (ShareIt handling not yet here). But if it is urgent,
just contact me.

Hope you like it and I am looking forward to comments, critics and suggestions.

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] Review process for new packages

2006-10-18 Thread Hans-Peter
2006/10/18, Anupam Tyagi [EMAIL PROTECTED]:
 Although, this is a sensitive issue, it is unfortunate that such review (or
 comment, if that is a more suitable word) process is not available at R.

Matlab has a nice system with reviews and metrics. See e.g.
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=174objectType=file

I also like the grouping in categories, see
http://www.mathworks.com/matlabcentral/fileexchange/loadCategory.do

But this is probably more a question of how complex the web site should be.

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] NULL or NA for missing function arguments?

2006-10-16 Thread Hans-Peter
Hi,

I am troubled by the use of NULL or NA to indicate
missing/non-specified function arguments.

In the R code that I have looked at, it seems that both forms are used
(NULL seems to be used more often though). Sometimes both variants are
in the same declaration, e.g.

format.default -
function(x, trim = FALSE, digits = NULL, nsmall = 0,
 justify = c(left, right, centre, none),
 width = NULL, na.encode = TRUE, scientific = NA,
 big.mark = , big.interval = 3,
 small.mark = , small.interval = 5, decimal.mark = .,
 zero.print = NULL, ...)

Is there a right way? And if both forms are used, how do I know which
one is right?

Thanks a lot and best regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] NULL or NA for missing function arguments?

2006-10-16 Thread Hans-Peter
2006/10/16, Duncan Murdoch [EMAIL PROTECTED]:
 As Gabor said, the third way is to give no default, but test missing()
 in the code.

I forgot this one, thank you. In my case it is probably not suited as
I just pass the arguments to a C (Pascal) function and do the checking
there.

[explanations snipped]
 So generally my advice would be:
 - Be consistent with similar existing functions.
 - Choose what you think will be convenient in current and predicted
 future versions of your function.

Ok, thank you. - Until now I always used NA but will (apart from your
advice) prefer NULL from now on. In C (Pascal) code NULL is also
easier to check than NA*

Thanks again and best regards,
Hans-Peter Suter


--
*
function riIsNull( _s: pSExp ): aRBoolean; cdecl;

vs.

function IsNaScalar( _x: pSExp ): boolean;
  begin
result:= (riLength( _x ) = 1) and
 (riTypeOf( _x ) in [setLglSxp, setRealSxp]) and
 (rIsNa( riReal( riCoerceVector( _x, setRealSxp ) )[0] )  0);
  end;

__
R-help@stat.math.ethz.ch 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] xlsReadWrite version 1.1.1 available

2006-10-07 Thread Hans-Peter
An updated version 1.1.1 of xlsReadWrite has been submitted to cran.
Currently the cran version is still 1.0, but you can download the
updated version already here: http://treetron.googlepages.com.

xlsReadWrite is a package which allows you to natively read and write
Excelfiles (windows only).

Changes from xlsReadWrite 1.0.0 to 1.1.1

- added colClasses argument (rowname, integer, double, factor,
   character and NA to determine type of data.frame column)

- NA values are no longer written into the Excelsheet.
- vector will be written as a column instead of a a row

- FIXED IMPORTANT BUG which could happen in rare cases in a RKRecord
   cell and led to numbers not divided by 100, e.g. wrong by this factor.
   (thanks to Eric Rexstad for reporting!)

- fixed bug with colNames: character vector in colNames didn't
   have an effect, I always used the Excel header row
- compiled with range checks enabled (this should have been
   done from the beginning; from now on programming errors
   surface properly as range check errors).
- minor changes in help text, README, testscripts improved...

- LAST BUT NOT LEAST: clarified license text by granting an explicit
   right to freely distribute and use this package incl. the dll.
   (my own source is still licensed as GPLv2 (same as before)).
Removed R-copyright notices in my source (had been there as
a kind of credit but can be misunderstood)).


-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] drop

2006-09-28 Thread Hans-Peter
Hello,

What's the best/recommended way to drop the dimension of a data.frame?
Probably test[,,] but I am not sure. I would prefer an explicit
function, but drop doesn't work with frames and I didn't find
something in the helpfiles/mailarchive.

Example:

test - data.frame( x = 1:7 )

str( drop( test ) ) # still a data.frame

str( test[,, drop = TRUE] ) # ok
str( test[,,] ) # ok == IS THIS THE WAY TO DO IT?
str( as.integer( as.matrix( test ) ) )  # ok

str( drop( as.matrix( test ) ) )# ~ok, named integer
test2 - test
attributes( test2 ) - NULL
str( drop( as.matrix( test2 ) ) )   # ok


Thanks and best regards,
Hans-Peter

PS: how could I lookup the code for subsetting a data.frame. I suppose
that it is in data.frame.[

__
R-help@stat.math.ethz.ch 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 index of elements in vector

2006-09-28 Thread Hans-Peter
2006/9/28, Cleber N. Borges [EMAIL PROTECTED]:
 Is There a fuction that return a index of a element in vector?
 like this semantic example:
 vector = c( 100, 200, 300 )
 getINDEX( vector, value = 200 )

which( vector == 200 )

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] fractional part

2006-09-28 Thread Hans-Peter
Hi all,

is there a function to get the fractional part of a number?

-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] fractional part

2006-09-28 Thread Hans-Peter
2006/9/28, Berton Gunter [EMAIL PROTECTED]:
 ?%%

I didn't know that operator, thanks!

But I was not clear, as I was looking more towards a lowlevel function.
E.g. trunc, floor, ceiling, ... are defined in names.c and while
I currently not fully understand this I thought there could be a
similair thing for fraction.

I defined the function frac - function(x) abs( x - trunc(x) )
which seems to work well.

Thanks again,
Hans-Peter

__
R-help@stat.math.ethz.ch 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] xlsReadWrite 1.0

2006-09-04 Thread Hans-Peter
The first version of xlsReadWrite has been uploaded to CRAN.


-- WHAT IS IT? / R COMMANDS

The package allows you to read and write Excel files natively. The supported
Format is BIFF 8, i.e. Excel from version 97 up to 2003.

• read.xls( file, colNames = TRUE, sheet = 1, type = data.frame, from = 1
)
• write.xls( x, file, colNames = TRUE, sheet = 1, from = 1 )


-- PLATFORM / LICENSE

Currently the package is only available on Windows (see also below).

The license is GPLv2 with an exception to allow the use of a third party
library (flexcel). With this exception the package as a whole becomes a
non-free package (according to the R license non-free packages are not
encouraged but at least possible/tolerated). See also README.

-- TECHNICAL BACKGROUND / PRO VERSION:

The core of this package is written in Delphi (PASCAL) and uses the R
headerfiles for Delphi which I have written earlier (see website below). For
the actual read/write operation in excel a proprietary library (Flexcel) is
used as I wouldn't be able to write this by myself and because for pascal
there are not open source libraries available. (AFAIK. - I am aware of
Apache POI (Java), a library for OpenOffice (C, too much work to translate
to pascal) and also some older one which don't support BIFF8).

I intend to make available (in 2 - 3 weeks) a pro version which has some
more functionality and formal support. As an independant developer I am
certainly happy if people will check this version out or consider a
contribution, but it is not my idea to play silly shareware games, the
open source version works well and I am commited to support it as far as I
can.

-- OTHER PLATFORMS (Linux/Mac)

Technically xlsReadWrite could be crossplatform. Flexcel already has a Kylix
version, which means that it could be made to run on Linux almost
immediately. The IMO better way would be to port the code to *FreePascal*:
this fits better in the open source world of R and this also would make it
possible to supply a Mac version. - While I started to port it, I didn't
succeed in the 2 days I have given me. - If there are any pascal-lovers
out there I would be very interested to get in touch, it would be more fun
to do it together than to try all by myself.


-- MORE INFOS / CONTACT:

At http://treetron.googlepages.com/ you will find an additional file with
testdata/-scripts and more infos (contact, bugs (currently nothing),
suggestions and todos).

I hope you enjoy using this package (I certainly do...) and am looking
forward to any feedback you might have.

Best regards,
Hans-Peter

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] embed image (png) in postscript (device)

2006-09-01 Thread Hans-Peter
Hi,

I output multiple grid-package-based plots to the postscript device.
Because the graphics are complicated and consists of a lot of datapoints
(~200'000) the files become really big. To avoid this big files and to
shorten the creation, I currently print the plots to the png device and
manually combine them into one multipaged pdf document.

My question is, it is possible to do this in R directly?
Probably I would have to create a png plot first, then reimport it into R
and put it on the ps device. Is this a realistic way (in principle) ?

If there is no package to read png files (I didn't find anything), I
probably could solve this. But I still don't know if it would be possible to
put this memory representation to a ps device.

Thanks for your time.

-- 
Regards,
Hans-Peter

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] hello Excel... (native/Package/BETA)

2006-06-20 Thread Hans-Peter
Dear list members

I am pleased to annonce that I have just finished a native Excel
reader/writer. It's wrapped up in two packages: either xlsReadWrite (open
source) or the slightly beefed-up xlsReadWritePro (shareware). Working
with Excel data is now as easy as writing read.xls and write.xls.

Some more details:

- Infos and download: http://treetron.googlepages.com
- for detailed documentation pls. download and see: help files, DESCRIPTION
and README.
- I set up a newsgroup for technical questions and feedback:
http://groups.google.ch/group/supportR

- while it could be ported to other platforms, currently it is WINDOWS only
(see technical below)
- native means, that the file will be read/written in binary form (without
needing Excel). The format is Excel version 97 - 2003

- xlsReadWrite and xlsReadWritePro both are powerful:
  - handle data.frames and matrices/vectors of type double, integer,
logical, character
  - allow to select sheets
  - support colNames and a title
  - lets you skip rows at the beginning of the file

- the Pro version additionally:
  - lets you select subdata (columns, rows or pick cells) in Excel
  - can have colClasses (currently mainly for rownames, more, e.g.
string-dates to come)
  - has xls.sheet: insert, select, delete sheets
  - has xls.open and xls.close: work with an xls-object in memory
  - has xls.info: gives information about file

- Technical/License:
  - it's written in Delphi (Pascal) and therefore Windows only
  - the open source compiler FreePascal potentially allows to compile for
other platforms
(http://www.freepascal.org/wiki/index.php/Platform_list).
[while I am interested in this for reasons of completeness, it's
unlikely that I will
look into it soon without somebody funding. The Linux people probably
won't care anyway
and just for macs, hmm, there are still much other things I'd like to
look into]
  - it's written by using the third party library
www.tmssoftware.com/flexcel.htm.
  - the open source version is GPLv2 and has an exception to allow linking
flexcel. Due
to this exception the package as a whole is non-free and non-standard.
  - the shareware package has a trial period which allows to check out for
anybody for free.
After the trial it has to be licenced for a small fee (or you can
reinstall it..., but I
hope not many people will do that!). It is also possible to license the
source code.

Suggestions, bug reports and other comments are very welcome. If possible I
try
to incorporate them in the gold version.

Best regards,
Hans-Peter

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] hello Excel... (native/Package/BETA)

2006-06-20 Thread Hans-Peter

   - the open source compiler FreePascal potentially allows to compile for
 other platforms
 (http://www.freepascal.org/wiki/index.php/Platform_list).
 [while I am interested in this for reasons of completeness, it's
 unlikely that I will
 look into it soon without somebody funding. The Linux people probably
 won't care anyway
 and just for macs, hmm, there are still much other things I'd like to
 look into]


I got an email which kind of said that my use of Linux people is
disrespectful and could imply that people who use Linux couldn't afford to
supply fundings.

It is *absolutely* not meant like this, I personally have Linux machines
(Debian, now Ubuntu) but currently use Windows more. My server is Suse. I
just wanted to express, that on linux afaik the people don't have the data
in xls-format and prefer the text format. It's from hearsay/newsgroup/and my
impression from a R-course. On Macs I personally know people who do a PhD
and have their data in Excel. So I though, they could be interested.

English is not my native language. Sorry for writing in a sloppy way.
Hans-Peter

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] strange digit switching

2006-06-19 Thread Hans-Peter
Hi,

I execute the following code snippet.What I don't understand is, that in the
first two cases the numbers shown don't correnspondant to the input (though
I have set the options to show 22 digits). When I assign the third number
which has one place, the display of the numbers is suddenly correct.

Can anybody explain what happens here?
(this is just a sample, my real problem lies in numbers that I import from a
datafile and I don't know how to control them when this switching occurs)

###
options( digits=22 )
x - matrix(NA, 3,1)
x[1] - 6.94788635771657950
x  # 6.947886357716580 # DIFFERENT ???
# NA
# NA
x[1] == 6.94788635771657950   # but is the same

x[2] - 8.34284937565404050
x  # 6.947886357716580 # DIFFERENT ???
# 8.342849375654041 # DIFFERENT ???
# NA
x[1] == 6.94788635771657950   # but is the same

x[3] - 0.19043842368566377
x  # 6.94788635771657950   # NOW OK!!!
# 8.34284937565404050   #
# 0.19043842368566377   #
x[1] == 6.94788635771657950   # but is the same


###
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  3.1
year   2006
month  06
day01
svn rev38247
language   R
version.string Version 2.3.1 (2006-06-01)


-- 
Regards,
Hans-Peter

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] program and comment

2006-04-26 Thread Hans-Peter
2006/4/26, Guojun Zhu [EMAIL PROTECTED]:
 Hi.  I am a newbie to R. I need to do a courses

*do* have a look at e.g.:
- http://cran.r-project.org/manuals.html (An Introduction to R)
- http://www.ms.unimelb.edu.au/~andrewpr/r-users/icebreakeR.pdf 
(contributed manual)
- http://cran.r-project.org/doc/contrib/Short-refcard.pdf  (reference-card)

to search the archives you can use:
- http://tolstoy.newcastle.edu.au/R/about.html
- http://finzi.psych.upenn.edu/search.html

 I am using R in Windows.

Have a look at Tinn-R  (editor)

 like mathemica.  I try to write the work into a little
 program for future reference. (My data soon exceeds
 the workplace.) So that should be a script, right?

yes

 Then I can load it in file/source R code.

source( yourScript.R )

check working path: getwd()
if you don't know what this is:
  ?getwd
  ?source

 First, can anyone confirm that I took the correct
 approach for the problem?

yes

I understand R is quite
 different from program language like C/Pascal which I
 am familiar with and seems people write it with quite
 different style.

it's a functional language and inherits from LISP (Scheme). You need
to read the manual.

Second, can anyone show me some idea
 about how to write  the comment.  Thanks.

# this is a comment

--
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] No Discounts for Springer books (e.g. S Programming)?

2006-04-21 Thread Hans-Peter
Hi,

I want to buy the books Modern applied Statistics with S and S
Programming. Both are Springer books and according to the Discount
Info on the page books related to R
(http://www.r-project.org/doc/bib/R-books.html) subject to a 20 %
discount.

Unfortunatley the promotion code doesn't work. I already contacted
Springer but didn't get an answer.

Does someone know what happened with these discounts? I didn't find
anything related in the archives.

Thanks and best regards,
Hans-Peter

--
PS: if someone has a used or redundant copy for sale, don't hesitate
to contact me...  ;-)

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] No Discounts for Springer books (e.g. S Programming)?

2006-04-21 Thread Hans-Peter
Dear Augustin,

 What you have to do is to register in that web page or in Springer Alert,
 and when you order the books, the discount is applied to your order
 automatically.

Thanks a lot, that worked. One has to register and then the discount
token is applied. - For the record: Amazon was quite a lot cheaper, so
it became a would have worked...

Thanks again and best regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] is there a formatted output in R?

2006-03-11 Thread Hans-Peter
2006/3/11, Michael [EMAIL PROTECTED]:
 I just need to be able to call my clearscreen function from all of my
 other scripts...
 Where do I put my clearscreen function?
 Is there a command similar to include in C++?

You can put the clearscreen function in a file. Then just source it,
which - with my basic C know how - should be the same as include.

All sourced function will disapear if you clear the environment (rm(
list = ls())). So it's maybe a good idea to source the global
functions/files everytime before executing the other scripts.

Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] matlab-like constant matrix initialization?

2006-01-30 Thread Hans-Peter
 Suppose I have the following matrix which is a constant matrix I've copied
 from some other document:

 1.2  3.4 1.4 ...
 2.3  3.7 2.6 ...
 ...
 How do I make it into a matrix or array in R?
 What is the fastest way of initializing a constant matrix with this
 copy/pasted values?

you cannot just paste it, you have to adapt it either like this

x - matrix( c( 1.2, 3.4, 1.4,
  2.3, 3.7, 2.6 ),
  nrow = 2, byrow = TRUE)

or like this:

x - rbind( c( 1.2, 3.4, 1.4 ),
c( 2.3, 3.7, 2.6 ) )

The second is closer to ML's x = [1,2 3.4 1.4;2.3 3.7 2.6] but the
first is probably the more popular/recommended approach. If it's a
large matrix that you don't want to adapt manually I think the only
way is to go via an ascii text file.

I see that you come from Matlab and that you have asked some rather
basic questions. I really recommend you, that you read the manuals (as
indicated). And do read them 2 or 3 times as they are much denser than
the Matlab manuals.

If you are not able to attend a course (which IMHO is the best way to
learn R) I'd buy a book.
(http://www.r-project.org/doc/bib/R-publications.html). Maybe the
John Verzani. Using R for Introductory Statistics or Uwe Ligges.
Programmieren mit R could help you.

Best regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Comments please, how to set your mailer to read R-help in digest format

2005-12-13 Thread Hans-Peter
2005/12/12, Michael Dewey [EMAIL PROTECTED]:

 There are occasional comments on this list about how difficult it is to
 read the digest format.

[snip]

Any other comments welcome of course.


I use google mail with a R-Label. In this way, all my R-Mails are
available in the R-Label-view and are searchable. The conversations are
instanteous updated and threadwise ordered. So it feels quasi the same as a
real newsgroup (which I would prefer btw).

[Well I think, it's a major space waste if everybody stores just the same
mails on his/her email account but since Google offers  1 GB space, who
cares].

Best regards,
Hans-Peter

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] www.krankenversicherung.ch News - Krankenkassen - Information Newsletter

2005-11-15 Thread Hans-Peter
Am 14.11.05 schrieb [EMAIL PROTECTED] [EMAIL PROTECTED]:
 [snip some spam]

Being located only some blocks away from these spammers, I just asked
them in person to remove the R list from their database.

Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] aggregate slow with many rows - alternative?

2005-10-14 Thread Hans-Peter
Many thanks for all your answers. Converting to a matrix didn't help,
I tried with Hmisc but didn't get anywhere (different summary
functions, multiple levels).

2005/10/14, jim holtman [EMAIL PROTECTED]:
 Here is the way that I would do it.  Using 'lapply' to process the list and 
 create a matrix

[snip]

Wow! That's a wonderful suggestion, Your code works just fine with my
data (takes 11 seconds). Thanks a lot, I couldn't have written such
code (reading some help entries now...).

Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] aggregate slow with many rows - alternative?

2005-10-13 Thread Hans-Peter
Hi,

I use the code below to aggregate / cnt my test data. It works fine,
but the problem is with my real data (33'000 rows) where the function
is really slow (nothing happened in half an hour).

Does anybody know of other functions that I could use?

Thanks,
Hans-Peter

--
dat - data.frame( Datum  = c( 32586, 32587, 32587, 32625, 32656,
32656, 32656, 32672, 32672, 32699 ),
  FischerID = c( 58395, 58395, 58395, 88434, 89953, 89953,
89953, 64395, 62896, 62870 ),
  Anzahl = c( 2, 2, 1, 1, 2, 1, 7, 1, 1, 2 ) )
f - function(x) data.frame( Datum = x[1,1], FischerID = x[1,2],
Anzahl = sum( x[,3] ), Cnt = dim( x )[1] )
t.a - do.call(rbind, by(dat, dat[,1:2], f))   # slow for 33'000 rows
t.a - t.a[order( t.a[,1], t.a[,2] ),]

  # show data
dat
t.a

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Kind of 2 dim histogram - levelplot

2005-07-05 Thread Hans-Peter
Dear R-List,

I've written some code to put measurement values at a position x and y
in bins (xb and yb). It works, but I wonder if there isn't a function
that would do what I do by hand in # fill data in bins?

Here is the code:

  # data
x - c( 1.1, 1.5, 2.3, 2.5, 2.6, 2.9, 3.3, 3.5 )
y - c( 6.3, 6.2, 5.9, 5.3, 5.4, 4.2, 4.8, 4.6 )
val - c( 50,  58,  32,  14,  12,  17,  36,  52 )
  # bins
xb - 1:4
yb - 4:7
xble - length( xb ) - 1
yble - length( yb ) - 1
  # fill data in bins
g - expand.grid( x=xb[1:xble], y=yb[1:yble] )
g$cnt - numeric( dim( g )[1] )
g$avg - numeric( dim( g )[1] )
g$proz - numeric( dim( g )[1] )

idx - 1
for (myy in 1:yble) {
  for (myx in 1:xble) {
xIdx - which( ( (x = xb[myx])  (x  xb[myx + 1]) ) )
yIdx - which( ( (y = yb[myy])  (y  yb[myy + 1]) ) )
bIdx - intersect( xIdx, yIdx )
g[idx,3] - length( bIdx )
g[idx,4] - sum( val[bIdx] )/g[idx,3]
g[idx,5] - sum(val[bIdx]0)/length(bIdx)*100
idx - idx + 1
  }
}
  # show data and plot
g
levelplot(cnt ~ x*y, g, main = Count, region = TRUE)


Best regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Possible bug in file.choose() - how to tell?

2005-06-15 Thread Hans-Peter
Hi,

I run a script file by dropping it on a windows batch file that runs R
in --slave modus. In a subfunction there is the call to file.choose().
The problem is, that the dialog does show only folders but no files at
all. It's quite strange: a) without --slave modus the files are shown,
b) when I copy the whole script file in a different file it was also
ok, but when I renamed the script, the dialog again only showed folder
names.

Questions:
- Is it appreciated if I submit a bug report on this issue? How would
I do it and to whom?
- I would like to have a look at the source code. As the prompt gives me:
   file.choose
  function (new = FALSE) 
  .Internal(file.choose(new))
  environment: namespace:base
  I suppose I had to download the source code of the base package and it would
  be C code. Is this right?

-- 
Best regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Possible bug in file.choose() - how to tell?

2005-06-15 Thread Hans-Peter
2005/6/15, Prof Brian Ripley [EMAIL PROTECTED]:
 OS? R version? Locale?

Win2000, SP4 - 2.1.0 - 
LC_COLLATE=German_Switzerland.1252; 
LC_CTYPE=German_Switzerland.1252;
LC_MONETARY=German_Switzerland.1252;
LC_NUMERIC=C;LC_TIME=German_Switzerland.1252

 This is a known problem with R 2.1.0 on Windows in some locales, solved
 long ago in R-patched.

True. It works perfectly with 2.1.0 patched. Thanks.

  PLEASE do read the posting guide! 
  http://www.R-project.org/posting-guide.html
 Yes, that does apply to you!  Please do supply the basic information it
 asks for.  If you want to allege a bug, so read carefully the section on
 BUGS in the FAQ.

Ok. - For the next time: could I have found out myself, that this was solved? 
(I did search the mail archiv and the r-project website; and also had
a look at the NEWS)

Thanks again and best regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] dir() and RegEx and gsub()

2005-06-10 Thread Hans-Peter
2005/6/9, Sarah Goslee [EMAIL PROTECTED]:

 Under R, for reasons I've never quite understood,
 \\. evaluates to .

Thanks to the answers of B. Ripley and Gabor I think, I understand now:

  1)  the patter-string \\.csv$ gives the regular expression \.csv$
  2)  now the backslash lets the dot to be interpreted literally
  (instad of a metacharacter). As said by Gabor, an alternative is,
  to put the dot between brackets

If you mean you want to change the \ to either \\ or / I'm
really not sure.

Yes that's what I intended. 
Because in windwos I copy the path from the address bar of the
explorer and paste it in the R console window. Now I *have* something
like
myfile - D:\UebungenNDK\DataMining\DataMiningSeries.r
that needs to be adjusted manually ;-(

I interpret the answers

 myfile - D:\UebungenNDK\DataMining\DataMiningSeries.r
I am sure that's not what you intended.  It has to be written as
 [snip] [1]  D:/UebungenNDK/DataMining/DataMiningSeries.r

and 

 myfile - D:\UebungenNDK\DataMining\DataMiningSeries.r
Variable myfile, as you have written it above, has no backslashes in it
so there is no way way to know where they are supposed to be. 

that it's not possible at all to have a character string with
backslashes in it (because they *will* act as escape characters).

- Maybe I could get along by writing an *external* function that would
give me back a proper formatted path, eg.
fold - as.path( D:\UebungenNDK\DataMining\DataMiningSeries.r )
[1] D:/UebungenNDK/DataMining/DataMiningSeries.r

- But then the behaviour would be different from all the other strings
in R which doesn't seem to be a good idea either

 I've always just processed the strings in vim or similar, rather
than fight with R.

I do it in DOS-Batch files. Quite ugly but it works...


Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] dir() and RegEx and gsub()

2005-06-09 Thread Hans-Peter
Dear R-Users,

I have two questions:

a)
in a directory there are 3 files:
[1] Data.~csvKopie von Data.~csv  VorlageTradefile.csv

The command dir( fold, pattern = \.csv ) gives back *all* the 3 files 
With dir( fold, pattern = \\.csv ) I get back only VorlageTradefile.csv. 
I don't understand this behaviour, IMHO the regex expression \.csv
becomes the string .csv and \\.csv becomes \.csv. So the first
string should catch it. This is also consistent with the result when I
tried with the TRegExpr Tool. Could somebody explain what's going on
here?

b)
I need to handle a copied windows file path. This is certainly often
asked but I didn't find a solution.
How can I convert, e.g.

myfile - D:\UebungenNDK\DataMining\DataMiningSeries.r
in either:

myfile
[1]  D:\\UebungenNDK\\DataMining\\DataMiningSeries.r

or:
myfile
[1]  D:/UebungenNDK/DataMining/DataMiningSeries.r

Would be great to hear about a possibility!

A nice evening to everybody,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] plots from batchfile on windows

2005-06-03 Thread Hans-Peter
Hi,

On windows I'd like to run a batchfile that leaves me a plot. As a
test I have the scriptfile test.r which only contains:

x - 1:10;
y - sample( 10 )
plot( x, y )

Now I tried the following (but nothing worked):

a) R --vanilla  test.r in the cmd window, = that doesn't give me a plot
b) the same, but I added bitmap(file=outplot.png) in the
scriptfile = Here I get an error that gswin32c.exe was not found.
(Maybe I need to install ghostscript???)
c) some attempts with Rgui.exe = I didn't arrive to pass a command argument.

It would be nice, to get some hints, how this could be done. I did
search the newsgroup archive, but unfortunately didn't find something.

Thanks and best regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] plots from batchfile on windows

2005-06-03 Thread Hans-Peter
On 6/3/05, Gabor Grothendieck [EMAIL PROTECTED] wrote:
 This was discussed previously this week.  Look right at the end of:
 https://www.stat.math.ethz.ch/pipermail/r-help/2005-June/071147.html

I had to add a win.graph... command, now it works:

x - 1:10;
y - sample( 10 )
win.graph(width = 7, height = 7, pointsize = 12)
plot( x, y )
savePlot( filename = test, type = png )

Great, thanks a lot for the tipp!

Hans-Peter



-- 
Regards,
Hans-Peter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html