Re: [R] XML package example code?

2009-11-24 Thread cls59


Peng Yu wrote:
 
 I'm interested in parsing an html page. I should use XML, right? Could
 you somebody show me some example code? Is there a tutorial for this
 package?
 

Did you try looking through the help pages for the XML package or browsing
the Omegahat website?

Look at:

  library(XML)
  ?htmlTreeParse

And the relevant web page for documentation and examples is:

  http://www.omegahat.org/RSXML/


-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/XML-package-example-code--tp26506445p26508065.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] SVM Param Tuning with using SNOW package

2009-11-17 Thread cls59


raluca wrote:
 
 Hello,
 
 Is the first time I am using SNOW package and I am trying to tune the cost
 parameter for a linear SVM, where the cost (variable cost1) takes 10
 values between 0.5 and 30.
 
 I have a large dataset and a pc which is not very powerful, so I need to
 tune the parameters using both CPUs of the pc.
 
 Somehow I cannot manage to do it. It seems that both CPUs are fitting the
 model for the same values of cost1, I guess the first 5, but not for the
 last 5.
 
 Please, can anyone help me!
 
 Here is the code:  
 
 data - data.frame(Y=I(Y),X=I(X))
 data.X-data$X
 data.Y-data$Y
 
 


Helping you will be difficult as we're only three lines into your example
and already I have no idea what the data you are using looks like.  Example
code needs to be fully reproducible-- that means a small slice of
representative data needs to be provided or faked using an appropriate
random number generator.  

Some things did jump out at me about your approach and I've made some notes
below.



raluca wrote:
 
 NR=10
 cost1=seq(0.5,30, length=NR)
 
 sv.lin- function(cl,c) {
 
 for (i in 1:NR) {
 
 ind=sample(1:414,276)
 
 hogTest-  data.frame(Y=I(data.Y[-ind]),X=I(data.X[-ind,])) 
 hogTrain- data.frame(Y=I(data.Y[ind]),X=I(data.X[ind,])) 
 
 svm.lin - svm(hogTrain$X,hogTrain$Y, kernel=linear,cost=c[i],
 cross=5)
 results.lin   - predict(svm.lin, hogTest$X)
 
 e.test.lin - sqrt(sum((results.lin-hogTest$Y)^2)/length(hogTest$Y))
 
 return(e.test.lin)
 }
 }
 
 cl- makeCluster(10, type=SOCK ) 
 


If your machine has two cores, why are you setting up a cluster with 10
nodes?  Usually the number of nodes should equal the number of cores on your
machine in order to keep things efficient.



raluca wrote:
 
 
 clusterEvalQ(cl,library(e1071))
 
 clusterExport(cl,c(data.X,data.Y,NR,cost1)) 
 
 RMSEP-clusterApplyLB(cl,cost1,sv.lin)
 


Are you sure this evaluation even produces results? sv.lin() is a function
you defined above that takes two parameters-- cl and c. clusterApplyLB()
will feed values of cost1 into sv.lin() for the argument cl, but it has
nothing to give for c.  At the very least, it seems like you would need
something like:

  RMSEP - clusterApplyLB( cl, cost1, sv.lin, c = someVector )



raluca wrote:
 
 
 stopCluster(cl)
 
 


Sorry I can't be very helpful, but with no data and no apparent way to
legally call sv.lin() the way you have it set up, I can't investigate the
problem to see if I get the same results you described.  If you could
provide a complete working example, then there's a better chance that
someone on this list will be able to help you.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/SVM-Param-Tuning-with-using-SNOW-package-tp26399401p26402903.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Error on reading an excel file

2009-11-16 Thread cls59


anna_l wrote:
 
 Hello everybody, here is the code I use to read an excel file containing
 two rows, one of date, the other of prices:
 library(RODBC)
   z - odbcConnectExcel(SPX_HistoricalData.xls)
   datas - sqlFetch(z,Sheet1)
   close(z)
 It works pretty well but the only thing is that the datas stop at row 7530
 and I don´t know why datas is a data frame that contains 7531 rows with
 the last two ones = NA...
 

I find this occurs sometimes when I export an Excel worksheet to CSV.  Excel
will include one or more rows of blank cells after the data stops.  I would
imagine the behavior you are seeing with RODBC is due to the same issue.

I don't know if there is anything that can be done about it other than to
trim your dataset back to the appropriate length once it gets into R.


Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/Error-on-reading-an-excel-file-tp26371750p26376554.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Error on reading an excel file

2009-11-16 Thread cls59


Gabor Grothendieck wrote:
 
 You could try one of the other methods of reading Excel files and see
 if they are affected:
 

I would guess that since Excel includes the blank rows when exporting to
CSV, then blank cells are being stored by Excel in the data files--
therefore any method of extracting data from those files will also pick up
the empty cells.

I think the crux of this issue lies with Excel and you will probably have to
look for a fix there.


-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/Error-on-reading-an-excel-file-tp26371750p26376915.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Sum over indexed value

2009-11-16 Thread cls59


Gunadi wrote:
 
 I am sure this is easy but I am not finding a function to do this. 
 
 I have two columns in a matrix. The first column contains multiple entries
 of numbers from 1 to 100 (i.e. 10 ones, 8 twos etc.). The second column
 contains unique numbers. I want to sum the numbers in column two based on
 the indexed values in column one (e.g. sum of all values in column two
 associated with the value 1 in column one). I would like two columns in
 return - the indexed value in column one (i.e. this time no duplicates)
 and the sum in column two. 
 
 How do I do this? 
 


Supposing you had the data:

  tstData - data.frame( index = c(1,2,1,1,3,2), 
value = c( 0, 4, 0, 0, 7, 4 ) )

You could use the by() function to divide the data.frame and sum the value
column:

  sums - by( tstData, tstData[['index']], function( slice ){

return( sum( slice[['value']] ) )

  })

However, by() tends to do a poor job of cleanly expressing which values of
'index' generated the sums.  I would recomend the __ply() functions in
Hadley Wickham's plyr package.  Specifically ddply():

  require( plyr )

  sums - ddply( tstData, 'index', function( slice ){

return(
  data.frame( sum = sum( slice[['value']] ) )
)
  })

  sums
   index sum
  1 1   0
  2 2   8
  3 3   7


Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/Sum-over-indexed-value-tp26376359p26378112.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] pairs

2009-11-16 Thread cls59


David Winsemius wrote:
 
 ?order
 

cindy Guo wrote:
 
 Do you mean if the numbers in each row are ordered? They are not, but if
 it's needed, we can order them. The matrix only has 5000 rows.
 

No, he's suggesting you check out the order() function by calling it's help
page:

  ?order

order() will sort your results into ascending or descending order.  You
could then pick off the top 50 by using head().

Hope that helps!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/pairs-tp26364801p26378236.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] extracting the last row of each group in a data frame

2009-11-16 Thread cls59


jeffc wrote:
 
 Hi,
 
 I would like to extract the last row of each group in a data frame.
 
 The data frame is as follows
 
 Name Value
 A 1
 A 2
 A 3
 B 4
 B 8
 C 2
 D 3
 
 I would like to get a data frame as
 Name Value
 A 3
 B 8
 C 2
 D 3
 
 Thank you for your suggestions in advance
 
 Jeff
 

Try using the base function by() or ddply() from Hadley Wickham's plyr
package:

  require( plyr )

  tstData - structure(list(Name = structure(c(1L, 1L, 1L, 2L, 2L, 3L, 4L),
.Label = c(A, 
B, C, D), class = factor), Value = c(1L, 2L, 3L, 4L, 
8L, 2L, 3L)), .Names = c(Name, Value), class = data.frame, row.names =
c(NA, 
-7L))

  lastRows - ddply( tstData, 'Name', function( group ){

return(
  data.frame( Value = tail( group[['Value']], n = 1 ) )
)

  })

  lastRows
Name Value
  1A 3
  2B 8
  3C 2
  4D 3


Hope this helps!


-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/extracting-the-last-row-of-each-group-in-a-data-frame-tp26378194p26378404.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Writing a data frame in an excel file

2009-11-16 Thread cls59


anna_l wrote:
 
 Hello, I am having trouble by using the write.table function to write a
 data frame of 4 columns and 7530 rows. I don´t  know if I should just use
 a sep=\n and change the .xls file into a .csv file. Thanks in advance
 


Base R cannot write .xls files by it's self.  You should output CSV using
write.csv():

  write.csv( dataFrame, file = 'results.csv' )

If you are using R on windows, then the RODBC package provides a mechanism
for dumping data frames directly to Excel files, possibly with multiple
sheets:

  require( RODBC )

  xlsFile - odbcConnectExcel( 'results.xls', readOnly = F )

  sqlSave( xlsFile, dataFrame, tablename = 'R Results', rownames = F )

  odbcCloseAll()


The tablename argument to sqlSave allows you to assign a name to the excel
sheet that will contain the data.frame.


-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26378547.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Error on reading an excel file

2009-11-16 Thread cls59



Gabor Grothendieck wrote:
 
 That doesn't necessarily follow since the various methods don't use
 Excel itself to create the csv file.
 

I was trying to point out cases where I have seen this behavior and R wasn't
involved.  Now that I think about it, I have observed to blank cells in a
Google Docs spreadsheets that were created from .xls files.

My point is that Excel, not R, may be the common denominator in this
problem.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/Error-on-reading-an-excel-file-tp26371750p26383479.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] pairs

2009-11-15 Thread cls59



cindy Guo wrote:
 
 Hi, All,
 
 I have an n by m matrix with each entry between 1 and 15000. I want to
 know
 the frequency of each pair in 1:15000 that occur together in rows. So for
 example, if the matrix is
 2 5 1 6
 1 7 8 2
 3 7 6 2
 9 8 5 7
 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return
 the value 2 for this pair as well as that for all pairs. Is there a fast
 way
 to do this avoiding loops? Loops take too long.
 
 Thank you,
 
 Cindy
 

Use %in% to check for the presence of the numbers in a row and apply() to
efficiently execute the test for each row:

 tstMatrix - matrix( c(2,5,1,6,
1,7,8,2,
3,7,6,2,
9,8,5,7), nrow=4, byrow=T )

  matches - apply( tstMatrix, 1, function( row ){
   
if( 2 %in% row  6 %in% row ){

  return( 2 )

} else {

  return( 0 )

}

  })

  matches
  [1] 2 0 2 0

If you have more than one pair, it gets a little tricky.  Say you are also
looking for the pair (7,8).  Store them as a list:

  pairList - list( c(2,6), c(7,8) )

Then use sapply() to efficiently iterate over the pair list and execute the
apply() test:

  matchMatrix - sapply( pairList, function( pair ){

matches - apply( tstMatrix, 1, function( row ){

  if( pair[1] %in% row  pair[2] %in% row ){

return( pair[1] )

  } else {

return( 0 )

  }

})

return( matches )

  })

  matchMatrix

   [,1] [,2]
  [1,]20
  [2,]07
  [3,]20
  [4,]07



If you're looking to apply the above method to every possible permutation of
2 numbers that may be generated from the range of numbers 1:15000... that's
225,000,000 pairs. expand.grid() can generate the required pair list-- but
that step alone causes a memory allocation of ~6 GB on my machine.

If you don't have a pile of CPU cores and RAM at your disposal, you can
probably:

  1. Restrict the upper end of your range to the maximal entry present in
your matrix since all other combinations have zero occurrences.

  2. Break the list of pairs up into several sublists, run the tests, and
aggregate the results.

Either way, the analysis will take some time despite the efficiencies of the
apply family of functions due to the shear size of the problem.  If you have
more than one CPU, I would recommend taking a look at parallelized apply
functions, perhaps using a package like snowfall,  as the testing of the
pairs is an embarrassingly parallel problem.

Hopefully I'm misunderstanding the scope of your problem.


Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/pairs-tp26364801p26365206.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Best advice for connect R and Octave

2009-11-14 Thread cls59


Jason Rupert wrote:
 
 I see at one time there was a package called ROctave.  I tried to install
 that package:
 
 install.packages(ROctave)
 --- Please select a CRAN mirror for use in this session ---
 Warning message:
 In getDependencies(pkgs, dependencies, available, lib) :
   package ‘ROctave’ is not available
 
 Unfortunately it appears that the package is no longer available. By any
 chance is there another package or series of steps that need to be
 followed to allow R to interface with Octave on the Window platform (not
 using Cygwin)?  
 
 

ROctave appears to be an Omegahat package-- and a rough one at that as it
has not been loaded onto the Omegahat CRAN-style server.  You can find info
at:

  http://www.omegahat.org/ROctave/

- Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/Best-advice-for-connect-R-and-Octave-tp26353037p26354485.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Transforming a dataframe into a response/predictor matrix

2009-11-12 Thread cls59


Ki L. Matlock wrote:
 
 I currently have a data frame whose rows correspond to each student and
 whose columns are different variables for the student, as shown below:
 
  Lastname Firstname CATALOG_NBR   Email StudentID   EMPLID
 Start
 1 alastname afirstname1213 *...@uark.edu  10295236 #
 12/2/2008
 2 anotherlastname anotherfirstname1213 *...@uark.edu  ##
 10295236 9/3/2008
   Xattempts Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15 Q16 Q17 Q18
 Q19
 1 1  1  1  0  0  0  0  0  0  0   1   0   0   1   1   0   1   1   0  
 1
 2 1  1  1  1  1  1  0  1  0  0   1   1   0   0   1   0   0   0   0  
 1
   Q20 Q21 Q22 Q23 Q24 Q25 Q26 Q27 Q28 Q29 Q30 Q31 Q32 Score Form
 CRSE_GRADE_OFF
 1   0   0   0   0   0   0   0   0   0   1   0   0   0 9E 
 D
 2   0   0   0   0   0   0   0   0   0   0   1   1   013G 
 D
 

Thanks for providing test data-- however this sort of format is difficult to
work with as email tends to mangle the line wrapping.  It took me about 5
minutes and the combined powers of Vim and OpenOffice to reflow and
re-export the example into a format that R could ingest.  And I probably
made a mistake somewhere along the way.  Nothing wrong with providing data
like this-- but it probably limits the number of people who are willing to
give your problem a try.

A good way to share test data frames if they contain a lot of rows/columns
is to dump them using the dput() function.  This encodes the data in the
following format:


structure(list(Lastname = structure(1:2, .Label = c(alastname, 
anotherlastname), class = factor), Firstname = structure(1:2, .Label =
c(afirstname, 
anotherfirstname), class = factor), CATALOG_NBR = c(1213L, 
1213L), Email = structure(1:2, .Label = c(*...@uark.edu, *...@uark.edu
), class = factor), StudentID = structure(c(2L, 1L), .Label = c(##, 
10295236), class = factor), EMPLID = structure(1:2, .Label = c(#, 
10295236), class = factor), Start = structure(c(14215, 14125
), class = Date), Xattempts = c(1L, 1L), Q1 = c(1L, 1L), Q2 = c(1L, 
1L), Q3 = 0:1, Q4 = 0:1, Q5 = 0:1, Q6 = c(0L, 0L), Q7 = 0:1, 
Q8 = c(0L, 0L), Q9 = c(0L, 0L), Q10 = c(1L, 1L), Q11 = 0:1, 
Q12 = c(0L, 0L), Q13 = c(1L, 0L), Q14 = c(1L, 1L), Q15 = c(0L, 
0L), Q16 = c(1L, 0L), Q17 = c(1L, 0L), Q18 = c(0L, 0L), Q19 = c(1L, 
1L), Q20 = c(0L, 0L), Q21 = c(0L, 0L), Q22 = c(0L, 0L), Q23 = c(0L, 
0L), Q24 = c(0L, 0L), Q25 = c(0L, 0L), Q26 = c(0L, 0L), Q27 = c(0L, 
0L), Q28 = c(0L, 0L), Q29 = c(1L, 0L), Q30 = 0:1, Q31 = 0:1, 
Q32 = c(0L, 0L), Score = c(9L, 13L), Form = structure(1:2, .Label =
c(E, 
G), class = factor), CRSE_GRADE_OFF = structure(c(1L, 
1L), .Label = D, class = factor)), .Names = c(Lastname, 
Firstname, CATALOG_NBR, Email, StudentID, EMPLID, Start, 
Xattempts, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, 
Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, 
Q18, Q19, Q20, Q21, Q22, Q23, Q24, Q25, Q26, 
Q27, Q28, Q29, Q30, Q31, Q32, Score, Form, CRSE_GRADE_OFF
), row.names = c(NA, -2L), class = data.frame)


Not very pretty, but this format is more resistant to email mangling and can
generally be copied/pasted into an R session-- saves all the monkey business
with Vim/OpenOffice/Excel/whatever.



Ki L. Matlock wrote:
 
 
 Each student took a pre- and post- test indicated by the date under
 Start, column 7.  (a date, mm/dd/, whose mm is 08 or 09 is pre-test;
 a date whose mm is 11 or 12 is post-test.  This test was one of four
 forms, E, F, G, or H, listed under Form, column 42. Each test had 32
 questions, Q1 to Q32, with a binary 1 indicating the student answered
 correctly to this question and 0 if incorrectly.
 
 I am needing a matrix, y, with five columns labeled: response, i, j, r, s. 
 Column 1 indicates the response (0 or 1) for i-th student, on the j-th
 question (1:32), on the r-th form (E,F,G,H- these could be changed to
 numeric 1 for E, 2 for F, etc.), on the s-th test (pre or post indicated
 by a binary 0 for pre, 1 for post).
 
 The data-set is very lengthy of approximately 2000 rows.  An efficient way
 to transform this data into the desired matrix would be very helpful. 
 Thank you.
 
 

The melt() function from Hadley Wickham's 'reshape' package can probably
take care of this for you.  Assuming the data.frame is named studentData,
the following might process your data the way you want it:

  require( reshape )

  # Retrieve the names of all columns holding responses to questions.
  questions - names( studentData )[ grep( '^[Q]', names( studentData ) ) ]

  testBreakdown - melt( studentData, c( 'StudentID', 'Form'), questions,
variable_name = 'Question' )


The first argument after the name of the data set specifies the names of
those columns that we wish to use in order to categorize the data. The
second argument specifies the names of columns that contain the data we are
interested in. testBreakdown is now a data.frame containing:

  A column labeled StudentID-- 

Re: [R] creating custom package and functions

2009-11-10 Thread cls59



dvkirankumar wrote:
 
 Hi all,
 I am new to R-project
 I have to create custom package and some required functions in that
 package
 can any one help me how to create a custompackage and how to write my
 function in to that package
 These things I have to use in many places as per requirements in my
 solution
 please help me to create these custom packages
 
 thanks in advance
 
 kiran.
 
 

Check out the Writing R Extensions manual:

  http://cran.r-project.org/doc/manuals/R-exts.html

If you just need to build and install a package containing some R functions,
then Section 1.1 and 1.3.2 probably contain what you need to know.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/creating-custom-package-and-functions-tp26296648p26296778.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to load a specific variable from an RData file?

2009-11-05 Thread cls59



Peng Yu wrote:
 
 Thank you. When the RData file is huge, it will take a long time to
 load it even though I may only need a small variable. Could somebody
 add an option to 'load()' to load only a few given variables?
 
 

Check out the filehash package. It has an option that allows you to store
variables in single-file databases just like RData files.  However, with
filehash data files, you can pick and choose which variables to load.

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/How-to-load-a-specific-variable-from-an-RData-file--tp26224416p26225433.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to load a specific variable from an RData file?

2009-11-05 Thread cls59



Peng Yu wrote:
 
 
 How to remove the environment 'e1' after I get 'nfree'?
 
 

Did you try rm( e1 ) ?

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/How-to-load-a-specific-variable-from-an-RData-file--tp26224416p26226191.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Help with RGDAL

2009-11-04 Thread cls59



Michael D. wrote:
 
 Hi Charlie!
 
 Sorry to jump in here so late but I just gave this a try. I usually
 install rgdal from CRAN on windows or download the binary from
 http://www.kyngchaos.com for Mac. I wanted to try your method from
 building from source since the directions were so clear and
 understandable. This is the first time I have done this and I am not
 very terminal savvy.
 
 I ran the last command above and get this message:
 
 
 * installing to library
 ‘/Library/Frameworks/R.framework/Resources/library’
 * installing *source* package ‘rgdal’ ...
 gdal-config: /Library/Frameworks/GDAL.framework/unix/bin/gdal-config
 /Library/Frameworks/R.framework/Resources/bin/config: line 143: make:
 command not found
 checking for gcc... no
 
 *SNIP*
 
 It seem to be looking for the C compiler among other things. Can you
 provide any help on this?
 
 Thanks in advance,
 Michael
 
 


Hi Micheal,

It looks like the Configure script couldn't find the make command and the C
complier-- this most likely means you haven't installed the Developer
Tools from your OS X cd.  This installation adds programs such as make and
gcc to your system.

Try opening the Optional Installs folder on the OS X cd and look for a
installer that says Xcode.  Run that installer and you should have
everything you need to build from source.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/Help-with-RGDAL-tp26135289p26199429.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] unexpected results in comparison (x == y)

2009-11-04 Thread cls59



Peter Tillmann wrote:
 
 Dear readers of the list,
 
 I have a problem a comparison of two data from a vector. The comparison
 yields FALSE but should be TRUE. I have checked for mode(), length() and
 attributes(). See the following code (R2.10.0):
 
 *SNIP*
 
 ZZ[4]
 [1] 0.02
 ZZ[5]
 [1] 0.02
 ZZ[4] == ZZ[5]
 [1] FALSE
 
 *SNIP*
 
 

This looks like a side effect of roundoff error due to the finite precision
of numbers stored by a computer.  There was a large discussion of this issue
on the list about two weeks ago, you could read the posts at: 

  http://old.nabble.com/Rounding-error-in-seq%28...%29-ts25686630.html

They may provide some insight.  The punchline is that:

  0.2 = 2 * (1/10)

And 1/10 is not representable as a form of:

  2^n

For some integer n. Therefore the number 0.2 cannot be represented exactly
in floating point arithmetic and so inconsistencies will occur-- as you just
observed.  It's one of those realities of computer science that always
catches us non-computer scientists by surprise.

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/unexpected-results-in-comparison-%28x-%3D%3D-y%29-tp26195749p26208361.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R crashes

2009-10-30 Thread cls59


premmad wrote:
 
 Windows XP 32 bit machine.
 allocated 2gb as memory for R 2.9.2
 data  will be 20mb and was running calculations on the data .
 but the r crashes with out any warning or so.
 

Ahh, well 20 MB is not huge data for R, so there should be no problem with
processing it. The pertinent questions now are:

  * What does your data look like? A small representational sample will
suffice, preferably something that can be copied out of an email and pasted
into R.

  * What operations are you running when R crashes? In your first post you
mentioned R crashes frequently-- does this happen with many different data
sets, but the same operations? 

If you could provide us the data and functions that are being executed just
prior to the crash, then we may be able to help. But without a reproducible
example to test on our own machines, as suggested by the posting guide for
this mailing list, there is really nothing we can do to help with your
problem.


-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://old.nabble.com/R-crashes-tp26110355p26132909.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Help with RGDAL

2009-10-30 Thread cls59


Pablo Alvarez-2 wrote:
 
 
 Hello, 
 We (two mac users) have been attempting to install rgdal from
 http://www.kyngchaos.com/software:frameworks;, given that it is not
 available as a binary on the CRAN (binaries) of the Package Installer. 
 
 

The GDAL library contains an impressive collection of utilities and also
leverages several other libraries such as HDF, netCDF and PROJ4, just to
name a few. Building and distributing a binary R package that contains the
GDAL library bloats the size of the package and causes redundancies if a
user already has GDAL installed somewhere else on their system. It also
creates a lot of extra work for the package maintainer.

This is probably done for Windows because a run-of-the-mill Windows system
is utterly incapable of building anything from source. Linux and OS X
systems are perfectly capable, so it is expected that you can build the
package from source and use your installed version of GDAL.



Pablo Alvarez-2 wrote:
 
 
 I have also tried to solve this problem by looking on the net for an old
 question, and though I have found it, the answers do not help very much
 because our porgraming skills are embryonic. 
 
 
 Our GIS professor has suggested we ask you guys how to proceed with the
 CRAN (source). Any suggestions or direction to an old document dealing
 with this?
 
 Thank you very much for your help, 
 Pablo and Margarita
 PS. We have already installed: GDAL (for QGIS) and sp (for R)
 
 

I've built the GDAL library and installed rgdal a few times-- it's typically
one of the first things I do after wiping or reinstalling my OS X system or
a Linux system. Building software from source can be a tricky business with
a steep learning curve-- but once you figure out some of the patterns it
becomes quite doable (as long as those darn platform-specific issues don't
cut you off at the kneecaps).

The rgdal package contains a Configure script that is run during
installation and attempts to locate the GDAL library. When building software
on Unix/Linux, there are three kinds of folders containing various items of
interest that compilers and linkers will frequently pester you about. These
are:

  * lib folders-- these contain libraries that hold code you are trying to
use.

  * include folders-- these contain header files that tell the compiler
how to use 
 the code in the libraries.

  * bin folders-- these contain scripts and programs that may help the
Configure script,
 or the program you are building do the things they do.

I suspect the Configure script for the rgdal package only checks standard
Unix/Linux folders such as /usr/bin or /usr/local/lib. The Framework package
provided by William Kyngesburye installs GDAL Mac-Style, which means these
folders are located in:

  /Library/Frameworks/GDAL.framework/unix/

And 

  /Library/Frameworks/PROJ.framework/unix/

Fortunately, R allows us to pass hints to configure during package
installation in order to help it find what it is looking for.

So, grab the source tarball of rgdal from:

  http://cran.r-project.org/web/packages/rgdal/index.html

I'm also using the PROJ4 and GDAL frameworks installed by the GDAL Complete
framework, available from:

  http://www.kyngchaos.com/software:frameworks/

Also, make sure you have installed the Developer Tools contained on your
OS X System Software CD as these provide C compilers and other tools needed
to build the code in the rdal package.

Now pop open a Terminal. Assuming you saved the package in your Downloads
folder, execute the following.

  cd ~/Downloads
  R CMD INSTALL rgdal_0.6-20.tar.gz

R will start to install the package, and then wipe out with a message that
includes:

  Error: gdal-config not found
  The gdal-config script distributed with GDAL could not be found.
  If you have not installed the GDAL libraries, you can
  download the source from  http://www.gdal.org/
  If you have installed the GDAL libraries, then make sure that 
  gdal-config is in your path. Try typing gdal-config at a
  shell prompt and see if it runs. If not, use:
  --configure-args='--with-gdal-config=/usr/local/bin/gdal-config' echo with
appropriate values for your installation.


gdal-config is a little script who's sole purpose is to tell Configure
scripts whatever they want to know about a GDAL installation. Scripts and
programs that accompany a library are commonly installed in a bin folder.
So given what I've noted above about the install location used by the GDAL
framework, we can give rgdal's Configure script a hint:

  R CMD INSTALL --configure-args=\
   
--with-gdal-config=/Library/Frameworks/GDAL.framework/unix/bin/gdal-config
\  
rgdal_0.6-20.tar.gz  

The R installer now spits out another error:

  Error: proj_api.h not found.
  If the PROJ.4 library is installed in a non-standard location,
  use --configure-args='--with-proj-include=/opt/local/include'
  for example, replacing /opt/local/* with appropriate values
  for your installation. If PROJ.4 is not installed, 

Re: [R] Re ading and Creating Shape Files

2009-10-29 Thread cls59


PDXRugger wrote:
 
 Hello R Community,
I have imported a dataset which contain X Y coordinates and would like
 to recreate a shape file after some data analysis.  What i have done is to
 import some taxlot data and join them based on some criteria.  I want to
 check to see how well the joining went by reviewing the results in GIS.  
 
 A couple things.  I cant seem to import a shape file correctly using the
 maptools package and the readShapeSpatial.  I have tried 
 
 Building=file(data/input/BuildingShape/Building.shp)
 Bldg-readShapeSpatial(fn=data/input/BuildingShape/Building,proj4string=NAD83)
 #--
 Bldg-readShapeSpatial(data/input/BuildingShape/Building,proj4string=NAD83)
 #---
 Building=file(data/input/BuildingShape/Building.shp)
 Bldg-readShapeSpatial(Building,proj4string=NAD83)
 
 I know i am mis interpreting the documentation but it doesnt seem like it
 is very complicated so i am of course confused.
 
 

I haven't used the maptools package for this kind of operation, so I offer
any specific advice. However, the value of proj4string seems to be a little
odd-- unless NAD83 is a variable that contains a string. It should probably
be a quoted list of PROJ4 declarations such as:

proj4string = '+proj=longlat +datum=NAD83'

If maptools is leveraging the sp package, then you probably need to enclose
the string in the CRS() function:

proj4string = CRS('+proj=longlat +datum=NAD83')

Note that the above example assumes coordinates are in lat/lon using the
NAD83 datum. If your data is in a different projection, such as UTM, you
will need to change the PROJ4 string accordingly.



PDXRugger wrote:
 
 
 Also, i am wondering if i can create a shape file by simply using XY
 coordinates from a data frame.
 So for:
 
 
 Ycoord=c( 865296.4, 865151.5, 865457.0 ,865363.4 ,865311.0, 865260.9
 ,865210.7 ,865173.3,
 865123.6 ,865038.2 ,864841.1 ,864745.4 ,864429.1 ,864795.6 ,864334.9
 ,864882.0)
 
 Xcoord=c( 4227640 ,4227816 ,4228929 ,4228508 ,4229569 ,4229498 ,4226747,
 4226781, 4229597,
 4229204, 4228910, 4228959 ,4229465 ,4229794 ,4229596 ,4229082)
 
 Lot-c(1900 , 2000,  2100  , 100   ,200  , 300,   400 ,  500 ,  600 ,  701
 ,  900 , 1000 , 1100,
   300   ,100,   200)   
 
 XYcoord-spCbind(Ycoord,Xcoord) #doesnt work so
 
 XYcoord=c(Ycoord,Xcoord)
 
 TaxLots-cbind(Ycoord,Xcoord,Lot)
 
 writeSpatialShape(XYcoord, TaxLots..,
 file=data/input/test/Taxlots,strictFilename=FALSE)
 
 
 
 So help reading in shape files and then creating them using XY coordinates
 if possible
 Any help would be appreciated.  Thank you.
 
 
 

Maybe maptools provides a nice way to do this-- again I haven't used it
much. My shapefile workflow usually centers on the sp and rgdal packages.
First, sp is used to create a spatial object that holds the coordinates and
data. Assuming you have point data:

  require(rgdal)
  lots - SpatialPointsDataFrame( coords = cbind(Xcoord,Ycoord), data =
data.frame( Lot = Lot ))

*Note that SpatialPointsDataFrame also takes a proj4string argument of the
form:

proj4string = CRS( 'proj declarations' )

I have omitted it since I don't know what projection your data is in.


You can then create a shapefile using the writeOGR() routine in rgdal:

  writeOGR( lots, dsn = 'tstShapefile', layer = 'tstShapefile', driver='ESRI
Shapefile')


The readOGR() function can also be used to read a shapefile-- note that you
give it the name of the directory containing the shapefile components and
not the name of an individual component such as 'shapefile.shp'.

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Reading-and-Creating-Shape-Files-tp26098828p26114143.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R crashes

2009-10-29 Thread cls59


premmad wrote:
 
 My R crashes frequently when run  with huge data.
 


I'm afraid this is nowhere near enough information for anyone on this list
to provide any sort of meaningful insight. At the very least we need to
know:

  * What operating system are you using?

  * Specifically, for large data set questions-- are you running a 32 or
64 bit operating system and how much RAM do you have?
 
  * What version of R are you running?

  * What does your data set look like and where does it come from?

  * How big is the data set?

  * How are you trying to read the data in?

You don't need to provide the complete data set-- just a representational
sample that someone interested in your problem could replicate into
something of the appropriate size. This is very critical as it is very
possible that the problem is arising from feeding R corrupted data rather
than R simply choking because the data set is too big.

Without this information, the best you can hope for from this mailing list
is silence or a flippant response.


-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/R-crashes-tp26110355p26123323.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R 64 and R: using 64-bit versions of packages in R (32)

2009-10-23 Thread cls59



Richard Liu wrote:
 
 I'm running R 2.9.2 build 5464 on OS X 10.5.8.  Having encountered  
 memory allocation problems, I ran the problematic code in R64, the 64- 
 bit version of the same build.  When I attempt to load openNLP I  
 receive the error message that the 32-bit version that I had been  
 using does not run in R64.
 
 Assuming there is a 64-bit version, can I install and load it in R64  
 and, when I subsequently switch to R (32-bit), will 64-bit versions of  
 packages run there?  I'm trying to avoid constantly having to manually  
 switch between 32- and 64-bit versions of packages.
 
 Regards,
 Richard
 
 

I don't think they will. The problem comes when the package has some
compiled code, in the form of a shared library, that R needs to load. A
32-bit version of R cannot load a 64-bit shared library, and vice versa.

However, R should handle this by building/downloading a separate version of
each package for each architecture listed in:

  /Library/Frameworks/R.Framework/Resources/bin/exec

Whenever you run install.packages() or R CMD INSTALL. If you are having
trouble, try reinstalling the offending packages. If there are still
problems, it is probably because the 32 and 64 bit versions of R are not
sharing the same living space, so the installers don't know there are
additional architectures that need to be included.

If this is the case, I would recommend installing the quad-arch build from:

  http://r.research.att.com/

And then, depending on which processor you have, removing either ppc and
ppc64 or i386 and x86_64 from:

  /Library/Frameworks/R.Framework/Resources/bin/exec

To prevent unnecessary compiler headaches. 

Note you will also have to download the 64 bit version of the GUI from the
ATT page if you want to use the GUI with 64 bit R.

Good luck!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/R-64-and-R%3A--using-64-bit-versions-of-packages-in-R-%2832%29-tp26034947p26035109.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] how to create a new data type

2009-10-22 Thread cls59



Markus Weisner-2 wrote:
 
 I am working on a new package to do fire department analysis.  I am
 working
 with emergency dispatch data from different agencies that all contain the
 same information but have slightly different formats.  Typically the
 variable names and date-time formats are different.  I am getting pretty
 good at reading in and rearranging the data so that it is essentially in
 the
 same format, but it is common for me to have an occasional wrong variable
 name or data type.  These slight deviations wreak havoc on all my
 functions
 that are setup to automatically analyze the data (and require specific
 variable names and data types).
 
 I would like to create a new data type that has defined variable names and
 types (where I would be forced to have the data in the correct format). 
 If
 I had my own unique data type, each of my analysis functions could check
 to
 make sure that provided data has the correct data type ... thus
 eliminating
 all these little debugging operations I have to keep doing to get the
 functions to work right.
 
 Any suggestions on how to do something like this?  I have done some
 research
 online, but could not find any simple explanations of creating user
 defined
 object types.  Thanks in advance for your help.
 
 Best,
 Markus
 
 

Well, you can get this functionality buy defining an S4 class:

  require( methods )
  setClass( 'myClass', representation = representation( from = 'character',
to = 'character', 
number = 'numeric' ),
prototype = prototype( from = character(), to = character(), number = 0
),
validity = function( object ){
 
   if( obj...@number  0 ){
 
  return(The number must be positive!)

   }

return( TRUE )

}
  )

That will define a class containing three components-- two character vectors
named from and to and a numeric vector named number. You can give the
names of any class, such as 'list' or 'data.frame', as components of a S4
class. The prototype specifies that each value will default to a vector of
length 0 except in the case of the number which defaults to 0. The validity
is an optional custom function that performs specific checks on the class
members-- in this case it ensures that the value given for the number is
non-negative. Returning anything but TRUE from the validity function will be
interpreted as an error.

New objects of a given class are created using new():

  myObject - new( 'MyClass', from = 'foo', to = 'bar', number = 3 )

Components, known as slots, are accessed using the @ operator in much the
same way that list items are accessed using $:

  myobj...@number

[1] 3


I have to run, but for more info you check the documentation of the methods
package and the R wiki page on S4 has some pointers to other references.

Hope this helps!

-Charlie



-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/how-to-create-a-new-data-type-tp26010194p26011194.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Diffusion of particles inside a sphere

2009-10-22 Thread cls59


carferper wrote:
 
 Hello veryone,
 
 I am interested in the diffusion of particles inside a sphere, and its
 release through a small pore on the sphere surface. Unfortunately, I have
 not found the way to do this in R. Could you help me?
 
 Thank very much in advance for your help
 
 

I have used R for very similar types of simulations involving the movement
of groundwater through porous media-- so R definitely has all the tools to
set up and solve these types of models. It also makes it easy to obtain nice
plots of the solution.

However, if you are asking Is there a ready-made model for situation X?
the answer is most likely No, you will have to build it yourself. At the
minimum you will need to:

  * Define the governing equation that describes the situation you are
modeling.
  * Define any initial or boundary conditions that apply to the situation.
  * Choose an appropriate numerical or analytical solution method to solve
the governing equation subject to the initial and boundary conditions.

At that point, you may have questions such as Are there any packages that
implement numerical/analytical method Y? or I am trying to implement
numerical/analytical scheme Y in R, but it isn't working because the
calculation of Z appears to be wrong. Can you help?. These sorts of
questions are specific enough that the members of this list could probably
offer advice on how to implement the nuts and bolts of the operations.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Diffusion-of-particles-inside-a-sphere-tp26010166p26015673.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] .Call() function

2009-10-14 Thread cls59



sdlywjl666 wrote:
 
 Dear all,
  What is the usage of the .Call()?
 What is the meaning of the follows:

 S=.Call(RS_fractal_spectral_density_function_direct,x,as.vector(taper.),as.logical(center),as.logical(recenter),TRUE,as.integer(npad),COPY=rep(FALSE,6),CLASSES=c(rep(matrix,2),rep(logical,3),integer),PACKAGE=ifultools)
 

.Call() is similar to .C() in that it calls up a compiled C function from a
dynamic library that has been loaded by R. However there is one differece--
.C() is used to pass information using standard C variable types as:

.C( 'myFunc', x = as.integer( someX ), y = as.double( someY ), PACKAGE =
'myPackage' )

Note that as.integer() and as.double() are used to ensure C receives objects
of the proper type. This would be processed by a C function with the
following definition:

void myFunc( int* x, double* y ){

  // C-level monkey business

}

.Call() is different in that it passes variables as R structures rather
basic C types. Using .Call() you don't have to wrap the arguments in
coercion functions like as.double(). The .Call() interface also expects that
the C function will return an R object:

.Call( 'myFunc', someX, someY, PACKAGE = 'myPackage' )

The C function now looks like:

#include R.h
#include Rdefines.h

SEXP myFunc( SEXP x, SEXP y ){

  // C-level monkey business with R objects

}

The other main interface is .External() which gathers all the arguments into
a single SEXP which is passed to C. More information and examples of .C(),
.Call() and .External() can be found in sections 5.2 and 5.10 of the
Writing R Extensions manual.


sdlywjl666 wrote:
 
  
 And is a function of RS_fractal_spectral_density_function_direct?
 Can I get the detail of RS_fractal_spectral_density_function_direct?
 Thanks a lot!
  
 Best regards,
 Wang
 
 

That function exists as compiled code in a dynamic library loaded by the
ifultools package so there is no way to directly view it from the R console.
However, you can download the source tarball for ifultools from CRAN, untar
it and scan the C files in the source directory:

cd ifultools
cd src
grep RS_fractal_spectral_density_function_direct *

Which reveals that it lives in the file RS_fra_sdf.c


I hope this helps!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/.Call%28%29--function-tp25903072p25903325.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] S4 tutorial

2009-10-13 Thread cls59



Peng Yu wrote:
 
 I'm looking for some tutorial on S4. I only find the following one,
 which is not in English. Can somebody let me know if there is any
 introductory material?  I'm very familiar with OO and C++. If there is
 some material that suits my background, it will be great.
 
 https://stat.ethz.ch/pipermail/r-help/2009-January/184108.html
 
 

There is a list of talks, presentations and papers on the R wiki page for
S4:

http://wiki.r-project.org/rwiki/doku.php?id=tips:classes-s4

Perhaps something in there will help you out!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/S4-tutorial-tp25881467p25881726.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] splitting dataframe, assign to new dataframe, add new rows to new dataframe

2009-10-12 Thread cls59



wk yeo wrote:
 
 
 Hi, all,
 
 My objective is to split a dataframe named cmbine according to the value
 of classes. After the split, I will take the first instance from each
 class and bin them into a new dataframe, df1. In the 2nd iteration, I
 will take the 2nd available instance and bin them into another new
 dataframe, df2.
 
 
cmbine$names
 apple tiger pencil chicken banana pear
 
cmbine$mass
 0.50 100.00 0.01 1.00 0.15 0.30
 
cmbine$classes
 1 2 3 2 1 1
 
 

If possible, it would be helpful to provide sample data in a form that could
be copied and pasted directly into an R session, like so:

cmbine - data.frame( names = c('apple', 'tiger', 'pencil', 'chicken',
'banana', 'pear' ) )
cmbine['mass'] - c(0.50, 100.00, 0.01, 1.00, 0.15, 0.30)
cmbine['classes'] - factor(c(1, 2, 3, 2,1 ,1))

It saves people on the list a bunch of coping/pasting/quote adding. Another
quick way to do this is to use  the dump() which spits out the structure of
your object in a way that can be copied and pasted:

dump( 'cmbine', file='' )



wk yeo wrote:
 
 
 These are the results which I want to obtain:
 
df1
 classes  mass
 apple  0.50
 tiger  100.00
 pencil  0.01
 
df2
 classes  mass
 banana  0.15
 chicken  1.00
 
df3
 classes  mass
 pear  0.30
 
 Below shows what I have tried. The main problem I have = I don't know how
 to assign the selected instance into a new dataframe with a name which is
 generated 'on-the-fly' based on the value of j (the jth row).
 
 
 for (i in 1:3) {
 same_cell - cmbine[cmbine$classes == i, ]
 if (nrow(same_cell)!=0){
   for (j in 1:nrow(same_cell)){
 picked - same_cell[j, ]
 assign(paste(df, j, sep=), picked)
 #assign(paste(df,j, sep=), paste(df, j, sep=))
   }
 }
 
 

I'm assuming you want the results grouped by class, i.e. all the 1s in one
data frame all the 2s in another. This can be done with a slight
modification of your loop:

for (i in 1:3) {
  same_cell - cmbine[cmbine$classes == i, ]

  if (nrow(same_cell)!=0){
assign(paste(df, i, sep=), same_cell)
  }

}

However, the results I get aren't the same as the results you said you
wanted:

 df1
   names mass classes
1  apple 0.50   1
5 banana 0.15   1
6   pear 0.30   1

 df2
names mass classes
2   tiger  100   2
4 chicken1   2

 df3
   names mass classes
3 pencil 0.01   3


The R way of doing this is to use the by() function, which breaks a data
frame into sub-data frames based on a column of factors-- such as the
classes. For your example, it would be used as:

by( cmbine, cmbine[['classes']], function( df ){

  # Lots of stuff can happen inside this function, in this case we are
really
  # just returning the subset that got passed in.

  return( df )

})

cmbine[[classes]]: 1
   names mass classes
1  apple 0.50   1
5 banana 0.15   1
6   pear 0.30   1
--- 
cmbine[[classes]]: 2
names mass classes
2   tiger  100   2
4 chicken1   2
--- 
cmbine[[classes]]: 3
   names mass classes
3 pencil 0.01   3

The by() function returns a fancy list, each component of which can be
accessed using the [] operator.

Hope this helps!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/splitting-dataframe%2C-assign-to-new-dataframe%2C-add-new-rows-to-new-dataframe-tp25865409p25865911.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] gee: suppress printout

2009-10-12 Thread cls59



joshua wells wrote:
 
 
 Unfortunately, i run thousands of these and the output gets extremely
 lengthy. Is there any way to suppress this printout in R?
 
 Thank you,
 
 Josh
 
 

One function that comes to mind is sink() which allows you to redirect
output somewhere else, such as a file or /dev/null which on unix-like
systems is where unwanted data goes to die:

sink('/dev/null')

# Stuff you don't want to see.

sink()

# Stuff you do want to see.

If you happen to be using Windows, you may be able to achieve more or less
the same effect by sinking to a temporary file:

sink( tempfile() )

Another function that may be useful is capture.output()

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/gee%3A-suppress-printout-tp25866057p25866226.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Function Help

2009-10-11 Thread cls59



jimdare wrote:
 
 Hi there,
 
 I have created the function below:
 
 pirate-function(x){
 a-x-1; b-a/5; c-a-b;
 d-c-1; e-d/5; f-d-e;
 g-f-1; h-g/5; i-g-h;
 j-i-1; k-j/5; l-j-k;
 m-l-1; n-m/5; o-m-n;
 final-o/5;
 
 final
 }
 
 I want to run this function until the output ('final') is an exact integer
 (e.g. 893.0 rather than 893.78332).  I then need to find out what
 value of X (input) resulted in this integer.  Could someone please help? 
 I am relatively inexperienced at creating functions.
 
 Kind regards,
 James 
 
 


You could approach this problem by setting it up as an optimization problem
where the task is to guess the value of x such that the squared difference
between pirate(x) and your target value is minimized. The difference is
squared in order to ensure the optimizer attempts to drive the difference to
0 instead of -infinity. A function that calculates the squared difference
between any function evaluated at a point x and some target value is:

sqDiff - function( x, funObj, target ){

  return( ( target - funObj(x) )^2 )

}

You can then use R's nlm() function in an attempt to discover the value of x
that results in your target value of 893. This requires specifying an
initial guess p:

nlm( sqDiff, p = 5000, funObj = pirate, target = 893 )

$minimum
[1] 1.996023e-07

$estimate
[1] 13634.3

$gradient
[1] -3.72529e-14

$code
[1] 1

$iterations
[1] 3


The solver came up with an estimate of 13634.3 for x:

pirate( 13634.3 )
[1] 892.9996

Achieving a solution that provides the exact value of 893 is very unlikely
using numerical optimization since these techniques involve refining a
series of guesses until one of the guesses is good enough-- i.e. within
1*10^{-6} of your target value-- at which point the algorithm terminates.

To get an answer that provides the target number of 893 exactly you will
probably have to use a symbolic  solver-- the Ryacas or rSymPy packages
provide interfaces to computer algebra systems that may have the necessary
symbolic tools to help you here.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Function-Help-tp25848627p25849148.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Second y-axis --- alternative to par(new=

2009-10-07 Thread cls59



Rainer M Krug-6 wrote:
 
 Thanks - but if I want to have the histogram with counts (freq=TRUE), then
 I have exactly the situation I was talking about - sorry for not being
 clear:
 
 x - rnorm(200)
 hist(x, col = blue, freq = TRUE)
 lines(density(x), col = red, lwd = 2)
 
 i.e.
 left y-axis (histogram): count
 right y-axis (density estimate): probability density
 
 

When adding a second y-axis, I always rescale the plot with a call to
plot.window() rather than par(new=T). This rescales the plotting area while
still allowing low-level plotting functions like lines and points to be
executed:

x - rnorm(200)
hist(x, col = blue, freq = TRUE)

# recovering par('xaxp') uses the original x limits.
plot.window( xlim = range( par('xaxp')[1:2] ), ylim = range( density(x)$y ))

lines(density(x), col = red, lwd = 2)

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Second-y-axis-alternative-to-par%28new%3D-tp25782532p25787630.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Second y-axis --- alternative to par(new=

2009-10-07 Thread cls59


cls59 wrote:
 
 
 # recovering par('xaxp') uses the original x limits.
 plot.window( xlim = range( par('xaxp')[1:2] ), ylim = range( density(x)$y
 )) 
 
 

Actually, I misspoke. I believe the following is the voodoo you want for
exactly recovering the original xlimit:


  plot.window( xlim = range( par('usr')[1:2] ), xaxs = 'i', ylim = range(
density(x)$y )) 


Basically, par('xaxp')[1:2] only returns the extreme values of the tick
marks on the original x-axis-- using these can still cause points not to
line up. par('usr')[1:2] returns the coordinates of the left and right edges
of the plot screen. setting xaxs to 'i' causes R to use the xlimit exactly
as given and not to pad it by 4% in an attempt to make it pretty.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Second-y-axis-alternative-to-par%28new%3D-tp25782532p25787984.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Unable to load 'doBy' package

2009-10-06 Thread cls59


Lauren Szathmary wrote:
 
 Hi all,
 
 I am trying to load the doBy package, and I am getting the following
 error:
 
 library(doBy)
 Error in loadNamespace(i[[1L]], c(lib.loc, .libPaths())) :
   there is no package called 'Hmisc'
 Error: package/namespace load failed for 'doBy'
 
 

This error message means that doBy depends on the Hmisc package, which is
not installed. To ensure that a package is installed along with it's
dependencies, install packages using the dependencies = T option:

  install.packages('doBy', dependencies = T )

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Unable-to-load-%27doBy%27-package-tp25768101p25776865.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Modify base R functions in Rprofile.site

2009-10-04 Thread cls59



Yihui Xie wrote:
 
 Hi everyone,
 
 I want to modify two base R functions 'parse' and 'deparse'
 immediately after R has started, so I added some code in the file
 'Rprofile.site' under the 'etc' directory. Here is a simple example:
 
 parse=function(...){
 base::parse(...)
 }
 
 I'll get an error when I start R as follows:
 
 Error: cannot change value of locked binding for 'parse'
 
 Is there a solution for my problem? Please note that I *have to*
 override the function names. Thanks very much!
 
 


Hi Yihui,

I have had cause to do some some similar things to Sweave functions-- maybe
the following will help:

  # Find out where the function lives.
  env - as.environment( 'package:base' )

  # Crack the binding.
  unlockBinding( 'parse', env )

  # Replace the function.
  assignInNamespace( 'parse', function(...){
  
   # Your function here, or an object that contains it.

   }, ns = 'base' )

  # Relock the binding.
  lockBinding( 'parse', env )


Note that the above is *very* dark voodoo-- it may cause unforeseen
consequences.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Modify-base-R-functions-in-Rprofile.site-tp25735437p25739660.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Modify base R functions in Rprofile.site

2009-10-04 Thread cls59


Duncan Murdoch-2 wrote:
 
 
 Why not just modify their source, and rebuild R?
 
 Duncan Murdoch
 
 

In my case, the IT guys don't always provide the necessary tools and/or
permissions to do this. Which is why we are fortunate that R is so flexible
as to allow modification of core routines in some cases.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Modify-base-R-functions-in-Rprofile.site-tp25735437p25740138.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Modify base R functions in Rprofile.site

2009-10-04 Thread cls59


Yihui Xie wrote:
 
 
 Thanks a lot, Charlie. What a coincidence -- I'm also working on 
 Sweave functions. parse() and deparse() can make the code more tidy 
 (they are used in source() and RweaveLatexRuncode()), 
 
 RweaveLatex 
 function () 
 { 
 list(setup = RweaveLatexSetup, runcode = RweaveLatexRuncode, 
 writedoc = RweaveLatexWritedoc, finish = RweaveLatexFinish, 
 checkopts = RweaveLatexOptions) 
 } 
 environment: namespace:utils 
 
 but we can either (1) let R automatically 'tidy up' our code and 
 remove all the comments or (2) keep the comments but leave the 
 original code untouched. 
 
 I worked out a trick to preserve the comments while tidying up the R 
 code, and I want to replace parse() and deparse() with my customized 
 functions, in which case Sweave will keep the comments. 
 
 However, my functions will need base::parse() and base::deparse() to
 help me, therefore my real difficulty is, how to let Sweave use my
 functions to parse and deparse R code without really modifying them in
 the base enviroment? I'm using the command 'R CMD Sweave'. 
 
 

Well, if you want to alter the behavior of RweaveLatexRunCode(), it can be
done from within a Sweave file. This happens to be what I did to Sweave-- I
wanted a little more control over the specifics of how it formatted code
chunk output in the .tex file. The steps involved are:

1. Make a copy of the Sweave function makeRweaveLatexCoderunner(). Patch it
so that it generates a RweaveLatexRuncode() function of your liking.

2. Overwrite utils:::makeRweaveLatexCodeRunner using the method I described
previously.

3. Generate a new code runner function using your patched version of
makeRweaveLatexCodeRunner().

4. Search all environments for old versions of RweaveLatexRuncode() and
replace them with your patched one.

An example of this approach is used to build the tikzDevice vignette, you
can view it at:

http://github.com/Sharpie/RTikZDevice/blob/master/inst/doc/tikzDevice.Rnw

Look for the line that says Begin Mother of All R Hacks.




Yihui Xie wrote:
 
 
 If there is no neat approach, I'll change my question to: how to write a
 package,
 say, Sweave2, that can be run using command line 'R CMD Sweave2 file'?
 
 

This is also doable, at least for Linux and OS X systems that are installing
from source. You need to add a Make target that installs your script, named
Sweave2, into R_HOME/bin/ when the package is installed. This is the
approach we took in the pgfSweave package-- you can view an example at:

http://github.com/cameronbracken/pgfSweave/blob/master/src/Makevars

I hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Modify-base-R-functions-in-Rprofile.site-tp25735437p25743082.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Rounding error in seq(...)

2009-09-30 Thread cls59


Martin Batholdy wrote:
 
 hum,
 
 can you explain that a little more detailed?
 Perhaps I miss the background knowledge - but it seems just absurd to  
 me.
 
 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
 
 

Unfortunately this comes as an utter shock to many people who never take a
Computer Science course. I watch it nail engineering students all the time.

Basically, if you have a fraction and the denominator is not equal to 2^n
for some integer n, that fraction will NEVER be stored as an exact floating
point number-- instead it will contain some error due to concessions that
must be made in order to use an efficient binary number scheme.

These errors are generally small, but they do propagate-- especially if you
are carrying the same numbers through a large computation. A good example is
large-scale numerical solutions to nonlinear problems where iterative
algorithms are employed repetitively at each solution step. As the
calculation progresses the roundoff error can rot away the computational
soundness of the algorithm.

If this concerns you, I would suggest reading up on common internal
representations of floating point numbers as well as the propagation of
roundoff error.

At the very least I hope this revelation will instill an appropriate sense
of paranoia concerning the numbers calculated by those magic boxes sitting
on our desks.

-Charlie 

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Rounding-error-in-seq%28...%29-tp25686630p25687626.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] matrix exponential

2009-09-30 Thread cls59


Kon Knafelman wrote:
 
 
 Hi Guys,
 
 Im trying to find the exponential of a matrix.
 
 Can someone please help me do this?
 
 Thanks a lot
   
 


There was actually a very recent discussion of this, and related operations.
See:

http://www.nabble.com/implementation-of-matrix-logarithm-%28inverse-of-matrix-exponential%29-ts25628876.html

Also, some good advice for finding a function when you don't know it's name
but you do know what job it performs is to have R search all the help pages
in all the packages you have using the ?? command:

??'matrix exponential'

You will see the expm() function in the base package Matrix if you have a
newish version of R.



David Winsemius wrote:
 
 
 Didn't we just do this one?
 
 

Well, it was matrix logarithms-- but close enough :P



Good luck!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/matrix-exponential-tp25691819p25692117.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] re ading and analyzing a word document

2009-09-30 Thread cls59


PDXRugger wrote:
 
 Howdy Y'all, 
 
 So i am looking to read a word document in the following formats(.doc) or
 any type of accessible word processor software (e.g. text .txt, notepad,
 etc).  Had the ability to search certain words, for instance banana,
 peacock,Weapons Mass Destruction.  Then i could summarize and view
 the results.  i looked and the only thing i could find was the below where
 i want to analyze letter.doc and look for the words mentioned in quotes
 above.  Its aparently wrong but im wondering if this is even possible. 
 Please advise.  Thanks 
 
 In Solidarity
 JR
 

Well... you could make a vector of the words you want to find:

to.find - c( 'banana', 'peacock', 'Weapons' )

Read in the file...

file.text - readLines( 'myFile.txt' )

And recursively apply the grep command in order to determine which lines
contain matches for your words:

line.matches - unlist( lapply( to.find, grep, x = file.text ) )

It may do what you want for plain text files, as for Microsoft Word files...
well...

Sometimes there is a price to pay for using a closed proprietary binary
document format.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/reading-and-analyzing-a-word-document-tp25691972p25692279.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] re ading and analyzing a word document

2009-09-30 Thread cls59



PDXRugger wrote:
 
 Considering your instructions:
 
 #Define words to find
 to.find - c( 'the', 'is', 'are' ,'dr') 
 #Read in the file... 
 file.text - readLines( 'data/letter.txt' ) 
 #Count number of occurnces of deined word in text
 line.matches - unlist( lapply( to.find, grep, x = unlist(file.text[2]) )
 ) 
 
 Result:
 line.matches 
 [1] 1 1 1
 
 This is not right of course as there are actually four words and secondly
 becasue the searched words appear multiple times.  
 
 

The example I gave was only meant to identify those lines on which matches
occurred. Using x = unlist(file.text[2]) only feeds one line of the file
into the matching routine so the result indicates that all the matches were
on line 1-- the only line present for searching.

If you want to count the individual occurrences of the words on each line,
you may need to look at using a function such as gregexpr. grep only
indicates if a match or matches is present in a line of text-- gregexpr
indicates at which positions those matches occur in the line.

However, you may be getting to the point with this where R is no longer an
appropriate tool for this job. R is amazingly flexible it is possible that
it can give you what you want. However, R was not designed to perform text
processing-- Perl comes to mind as being a language that was explicitly
designed to perform these sorts of operations.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/reading-and-analyzing-a-word-document-tp25691972p25692881.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Teach me how to transpose in R

2009-09-27 Thread cls59



Hyo Lee wrote:
 
 
 Teach me how to deal with this problem.
 Thank you very much.
 
 -Hyo
 
 


A good thing to try if you're stuck finding the right function in R is
searching with ??. For example, if you type:

??transpose

The base routine t(), which performs a matrix transpose, is one of the first
things that comes up.

Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Teach-me-how-to-transpose-in-R-tp25630869p25631393.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Select.spatial on spplots

2009-09-27 Thread cls59



Julius Tesoro wrote:
 
 Hi everyone. I posted this on R-sig-geo but got no response. 
 
  
 Can select.spatial() be used in an existing spplot? I have tried selecting
 points (eq) from a plot generated from sp. However, when I invoke
 select.spatial(eq). It generates only the points without the background
 containing the faults. I need the background to select which earthquakes
 coalesce on which fault. Is there an alternative?
 
 eq.pts-list(sp.points,eq, col=blue, lwd=0.5, pch = 4)

 spplot(faults,Dip, xlim = c(11,12),
 ylim = c(376,389),
 sp.layout=list(eq.pts),
 col = heat.colors(3))
 
 select.spatial(eq)
 
 Cheers,
 
 Julius Tesoro
 
 


Unfortunately, it looks like select.spatial() wipes the plotting region by
executing it's own call to plot(). However, the function it's self is very,
very simple, just type:

select.spatial

To see what goes on inside. It looks like you could obtain point-wise
selection by just calling identify():

identify( coordinates( eq )[,1], coordinates( eq )[,2]

To use areas, call locator() and then process the results using
point.in.polygon().

As for whether this will work using a spplot-- I really couldn't say. I was
not able to reproduce a spplot using the information you provided-- lack of
a working example may be a reason you got nothing but silence on R-sig-geo.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Select.spatial-on-spplots-tp25632668p25635166.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Downloading data from from internet

2009-09-26 Thread cls59


Duncan Temple Lang wrote:
 
 
 
 However, you can use the source form of the package as a Windows
 user; you just have to install it. That involves finding out how to do
 this
 (either with Uwe's Windows package building service or by installing the
 tools
 that Brian Ripley and Duncan Murdoch have spent time making available to
 more easily use.)
 
 

As a footnote to this, the tools required to enable package building on
Windows are available at:

http://www.murdoch-sutherland.com/Rtools/

Download and run the installer for your version of R. Make sure you allow
the installer to modify your PATH. After installing the tools, you should be
able to build and install most packages from within R via:

install.packages( 'packageName', type = 'source' )



Duncan Temple Lang wrote:
 
 
 Generally (i.e. not pointing fingers at any one in particular), I do wish
 Windows users would learn
 how to do things for themselves and not put further burden on people who
 provide them with free
 software and free advice to also provide them with binary versions of
 easily
 installed packages. It does take time for us to maintain different
 operating
 systems and to create binaries. Running Windows and not being able to
 install
 R packages from source is a choice, not a technical limitation.
 
 
  D.
 
 

I echo this sentiment as well-- but personally I believe this is mostly a
symptom of Microsoft's decision to provide such a sorry excuse for a command
line in Windows. Most Windows users never even consider building from
source because it's not something that their operating system is capable of
doing out of the box.

This problem is further exacerbated by the fact that most IT departments go
to such ridiculous lengths to lock their users out of Windows in an attempt
to secure it. For example, I couldn't install Rtools on my workstation at
the university even if I wanted to-- luckily all of our computers can dual
boot into Linux.

The lack of a decent command line prestocked with common tools, such as Perl
and a C compiler, is the main reason I consider Windows an operating system
of last resort.

Here endeth the rant.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Downloading-data-from-from-internet-tp25568930p25627641.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] evaluate a set of symbols within an IF statement

2009-09-25 Thread cls59


zubin-2 wrote:
 
 
 how do i evaluate this whole list to a single boolean True or False?  If 
 any of these are true the whole statement is True, else False.   this 
 only seems to work for the first ticker, the rest don't perform the 
 operations within the loop.
 
 

Try %in%

tname %in% checkticker

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/evaluate-a-set-of-symbols-within-an-IF-statement-tp25620871p25620900.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Downloading data from from internet

2009-09-24 Thread cls59



Bogaso wrote:
 
 Hi all,
 
 I want to download data from those two different sources, directly into R
 :
 
 http://www.rateinflation.com/consumer-price-index/usa-cpi.php
 http://eaindustry.nic.in/asp2/list_d.asp
 
 First one is CPI of US and 2nd one is WPI of India. Can anyone please give
 any clue how to download them directly into R. I want to make them zoo
 object for further analysis.
 
 Thanks,
 

The following site did not load for me:

http://eaindustry.nic.in/asp2/list_d.asp

But I was able to extract the table from the US CPI site using Duncan Temple
Lang's XML package:

  library(XML)


First, download the website into R:

  html.raw - readLines(
'http://www.rateinflation.com/consumer-price-index/usa-cpi.php' )

Then, convert to an HTML object using the XML package:

  html.data - htmlTreeParse( html.raw, asText = T, useInternalNodes = T )

A quick scan of the page source in the browser reveals that the table you
want is encased in a div with a class of dynamicContent-- we will use a
xpath specification[1] to retrieve all rows in that table:

  table.html - getNodeSet( html.data,
'//d...@class=dynamicContent]/table/tr' )

Now, the data values can be extracted from the cells in the rows using a
little sapply and xpathXpply voodoo:

  table.data - t( sapply( table.html, function( row ){

row.data -  xpathSApply( row, './td', xmlValue )
return( row.data)

  }))


Good luck!

-Charlie
 
  [1]:  http://www.w3schools.com/XPath/xpath_syntax.asp

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Downloading-data-from-from-internet-tp25568930p25572316.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] save txt file

2009-09-23 Thread cls59


Eiger wrote:
 
 Hi, I have 2 questions:
 
 
 Question 1:
 
 I define 2  variables: a, b:
 
 a-rbinom(4,10,0.8)
 output:
 [1] 9 7 8 8
 
 b-rbinom(2,6,0.7)
 output:
 [1] 4 5
 
 if I write:
 write.table(a, file = filename, etc. etc.  )
 it save only the values of variable a.
 
 There is a way to save in a .txt file the values  a and b as
 consecutive data?  (but I would use many variables..)
 ..like this:
 
 9
 7
 8
 8
 4
 5
 
 Question 2:
 is possible save data as rows?  
 (9 7 8 8 4 5)
 
 thank's
 
 Eiger
 
 

Assuming you are dealing with vectors of numbers, you can form a row of
data using the append function to stick b onto the end of a:

 append( a, b )
[1] 9 7 8 8 4 5

This can be dumped to a file using write.table:

write.table( t( append(a,b) ), 'test.txt', row.names=F, col.names=F,
append=T )

The transpose function t() is used because write.table() assumes a singleton
vector is a column vector and you want row vectors.

If you have two matrices instead of vectors, say:

matA - matrix( rep(a,4), nrow=4, byrow=T )
matB - matrix( rep(b,4), nrow=4, byrow=T )

Then you would use the cbind() function instead of the append() function to
form your rows and drop the transpose function:

write.table( cbind(a,b), 'test.txt', row.names=F, col.names=F, append=T )

If you want to overwrite (i.e. start a new file) when you use write.table,
then drop the append=T.

Hope this helps!

-Charlie




-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/save-txt-file-tp25531307p25531324.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Creating loops with strings

2009-09-23 Thread cls59



Rakknar wrote:
 
 Hello. I'm trying to run a series of commands in two different datasets.
 For make it efficient I want to make a loop for it. Until now the only
 command for loops i found it's the for() command it's only for series of
 numbers and not a series of strings, witch it's what i'm needing. It would
 be something like this
 
 for(i in dataset1 dataset2) {
 i - read.dta(dataset1.dta)
 ls()
 summary(i)
 str(i)
 attach(i)
 }
 
 I hope the idea it's clear. I'm using 2.9.1 Windows Version of R.
 
 Thanks.
 

First, form a vector of the datasets you want to load:

data.sets - c( 'dataset1', 'dataset2' )

Then execute your loop:

for( set.name in data.sets ){

  data.file - paste( set.name, sep='' )

  assign( set.name, read.dta( file.name ), envir = .GlobalEnv )

  ls( envir = .GlobalEnv )

  summary( get( set.name, envir = .GlobalEnv ))

  str( get( set.name, envir = .GlobalEnv ))

}

Here, the assign() function is used to create a variable in the top-level
environment (given by .GlobalEnv) that has the same name as the current
value of set.name-- so two variables named dataset1 and dataset2 will be
generated by the loop. The contents of those variables are set to the return
value of read.dta().

Next, the get() function is used to retrieve the variables created by
assign() using the name stored in set.name-- this retrieved object is then
passed off to summary() and str().

Notice that I have excluded the attach() statement, although it could have
been applied to the datasets being loaded. Attach should only be used in
situations where you intend to use, but not modify, the contents of a list
or data frame. Even then it often produces results similar to shooting
yourself in the foot with a .44 magnum.

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Creating-loops-with-strings-tp25530899p25531328.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Creating loops with strings

2009-09-23 Thread cls59



cls59 wrote:
 
 
   data.file - paste( set.name, sep='' )
 
   assign( set.name, read.dta( file.name ), envir = .GlobalEnv ) 
 
 

Opps, those lines should have been:

  data.file - paste( set.name, '.dta', sep='' )

  assign( set.name, read.dta( data.file ), envir = .GlobalEnv ) 


Sorry for the confusion! 
(I need more coffee... or a nap)

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Creating-loops-with-strings-tp25530899p25531332.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Statistical analysis

2009-09-23 Thread cls59



Chris Li wrote:
 
 Hi all,
 
 I have got two datasets, one of them is rainfall data and the other one is
 groundwater level data.
 
 I would like to see whether there is a correlation between these two
 datasets and if there is, to what extent they are correlated.
 
 My stats background is limited, therefore any advice on which command I
 should use in R would be greatly appreciated.
 
 Thanks in advance.
 Chris
 


Supposing you have two variables-- precipitation, p, and groundwater
potential, h-- a simple test for linear correlation is to produce a
scatterplot of h vs. p:

plot( h ~ p )

If it looks linear, than it may be worthwhile to have R estimate the
coefficient of correlation for the data:

cor( p, h )

If the correlation coefficient is close to +/- 1, than your data is
exhibiting a strong linear trend and a linear model may be appropriate:

linModel - lm( h ~ p )

abline( linModel )


Good luck!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Statistical-analysis-tp25531331p25531335.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help with $ and % symbols in R

2009-09-18 Thread cls59



Edward Chen-3 wrote:
 
 Could someone explain to me briefly and point me to where I can find help
 on
 what the symbols $ and % mean in R? I have seen them in many others'
 codes,
 but I am still very unsure as to what they mean and what they do.
 Thank you very much!
 
 

Help pages for symbols like if, for, [, -, $ can be accessed in the same
way as help pages for functions. A pair of % signs is usually used to
delimit a special unary or binary operator-- such as %*% which invokes
matrix multiplication. However, since these symbols have special meaning,
they must be quoted when placed next to ? or ??-- like so:

?$

??%

- Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/help-with-%24-and---symbols-in-R-tp25515775p25516043.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] latex code in R - convert to pdf

2009-09-17 Thread cls59



Martin Batholdy wrote:
 
 is it possible to convert latex code to pdf in R (like a latex-program  
 would do it)?
 Is there a package that comes with this capabilities?
 

Unfortunately you're out of luck if you're seeking a direct path from LaTeX
code generated in R to pdf without passing through a LaTeX compiler.
Re-implementing the pdfTeX compiler in R would be a monumental undertaking
as the TeX macro-expansion language is pretty hairy-- low-level TeX can make
the worst Perl screen-vomit look tame by comparison.

And that's just TeX-- throw in a pile of LaTeX macro packages and the
difficulty shoots up another order of magnitude or two.


Martin Batholdy wrote:
 
 My problem is that I want to generate tables automatically -
 and I can't use a latex editor at that computer ...
 
 Besides latex ... are there good ways to generate tables in R?
 

There's the xtable package which can perform some automagical formatting of
R objects to LaTeX code. If you don't have access to LaTeX at a workstation,
you could try using xtable's HTML output mode-- then use Word or OpenOffice
to open the HTML file and copy the table.

There are also a few utilities out there that can perform a conversion from
TeX to HTML-- they might be worth Googling if xtable's HTML output isn't
working for you.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/latex-code-in-R--%3E-convert-to-pdf-tp25486430p25487067.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] dyn.load search path?

2009-09-17 Thread cls59



Steve Jaffe wrote:
 
 Sorry if this is somewhere in the fine manuals but I've been unable to
 locate it.
 
 Does dyn.load use a search path or does it just look in the current
 directory for non-fully-qualified filenames? If there is a search path,
 what is it?
 
 Thanks for your help
 

I believe dyn.load() will attempt to load a library from whatever path you
point it at, like so:

dyn.load('/path/to/dynamic/library')

If your dynamic library references code in other dynamic libraries, I would
imagine environment variables such as LD_LIBRARY_PATH would come into play--
but I'm not an expert on such voodoo.

If you would like a shortcut to loading libraries in certain places that R
knows about, such as the R package library, check out providing arguments to
dyn.load() using system.file() or loading package libraries using
library.dynam().

Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/dyn.load-search-path--tp25492214p25492224.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How can I use R:sort function in C code?

2009-09-15 Thread cls59



Guozhu.Wen wrote:
 
 Hi, I wrote a C extension for R. Within the C code I wanted to invoke the
 R's sort function, with the argument index.return = TRUE. I found it is
 a
 difficult problem, how can I do that? I have implemented the decreasing
 sorting by the code PROTECT(R_fcall = lang3(install(sort), x, desc));,
 but how to define the index.return argument?
 
 Thanks in advanced!
 
 -- 
 Guozhu. Wen
 
 

I found this a little tricky to do the first time-- but it's not bad at all
once you go through it. The steps I usually follow are:

1. Create an object to hold your function call.

2. Find the R function you want to call.

3. Prepare the function call by setting attributes on your object.

4. Execute the function call.

5. Recover data.

Unfortunately, I have to run to a meeting this morning so I can't write out
examples of all these steps. I suggest looking at section 5.11 of the
Writing R Extensions manual. Also, section 10.2 of the tikzDevice vignette
details an example of calling an R function from within a C function.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/How-can-I-use-R%3Asort-function-in-C-code--tp25450683p25455479.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] installation problem

2009-09-14 Thread cls59



wesley mathew wrote:
 
 Hello All
 
 I have some problem for installing  XML_2.6-0.tar . I am working in widows
 and R version is  R-2.9.1
 
 

Unfortunately, I think there are some problems with CRAN being able to build
the XML package for Windows, at least the page:

http://cran.r-project.org/web/packages/XML/index.html

Lists it as unavailable. However, I know I have installed it on a Windows
machine at the university using install.packages()-- R may be set up to pull
from some additional repository there. I'll check the next time I'm in the
lab.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/installation-problem-tp25438411p25439211.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Which apply function to use?

2009-09-14 Thread cls59



Masca, N. wrote:
 
 Dear All,
 
 I have a problem which *should* be pretty straightforward to resolve - but
 I can't work out how!
 
 I have a list of 3 coefficient estimates for 4 different datasets:
 
 Coefs-list(c(1,0.6,0.5),c(0.98,0.65,0.4),c(1.05,0.55,0.45),c(0.99,0.50,0.47))
 
 All I want to do is take the sum (or mean) of each coefficient across the
 4 datasets.  
 
 I can do this using a for loop, but it gets very messy - as I need to do
 this several times I was hoping someone might have a better solution using
 one of the apply functions.  Any ideas?
 
 Many thanks for any help you can provide.
 
 Cheers,
 
 Nick
 
 


Since Coefs is a list object you could use the lapply list apply function
to execute the mean() function on each component of the list:

lapply( Coefs, mean )

You could also use it to execute your own function that contains additional
operations:

lapply( Coefs, function( listComponent ){

  # Do whatever.

  mean( listComponent )

})

However, I don't know what you mean by these coefficients you want to
apply to each of the four data sets. Perhaps you could elaborate?

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Which-%22apply%22-function-to-use--tp25439192p25439276.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Location of Packages?

2009-09-14 Thread cls59



iaw4 wrote:
 
 
 PS: do I need to install the car packages under the 64-bit version, or
 will
 it be seen by the 64 bit version if I do a 32-bit install?  Or do I need
 to
 do a double install?  for safety, I did it under the command line version,
 which I presume is still 32-bit, and the 64 bit GUI.
 
 


Ooops, there was one point I wanted to clarify related to this. The
architecture of your machine only matters if the package contains code that
needs to be compiled-- i.e. Fortran or C routines. When installing packages,
R will automatically attempt build separate libraries with versions of these
routines for every architecture listed in:

/Library/Frameworks/R.framework/Resources/bin/exec

So you shouldn't need to worry about double installing or dual
building-- it should be taken care of for you. 

P.S
I have had some problems building ppc64 binaries from source on OS X when
installing packages. Since I am running an x86_64 machine, I have no need
for these binaries, so I simply removed the ppc64 folder from
/Library/Frameworks/R.framework/Resources/bin/exec to stop the builds.

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Location-of-Packages--tp25438651p25438910.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Location of Packages?

2009-09-14 Thread cls59



iaw4 wrote:
 
 Sorry, one more: on OSX, I deleted my old 2.9.2 R.app, and installed the
 64
 bit version of 2.9.0.  I then did an install.packages(car) under my
 new
 2.9.0.  It seems to have worked, but alas, I still get an error that
 package
 'car' was built under R version 2.9.2 .  Where exactly does R under OSX
 install its packages?  (is it a bug that another car is loaded?)
 

If you are using the standard install on OSX, then packages are kept in:

/Library/Frameworks/R.framework/Resources/library

If you installed the package from CRAN then I think the warning may be
related to CRAN using the most recent version of R to build packages. i.e.
you are running R 2.9.0, but the CRAN server was the actual builder of the
package you are using and it was running R 2.9.2.


iaw4 wrote:
 
 
 PS: do I need to install the car packages under the 64-bit version, or
 will
 it be seen by the 64 bit version if I do a 32-bit install?  Or do I need
 to
 do a double install?  for safety, I did it under the command line version,
 which I presume is still 32-bit, and the 64 bit GUI.
 
 

If you installed a distribution that includes both i386 and x86_64 versions
then R will be able to run in both modes, depending on the situation. Check
the folder names in:

/Library/Frameworks/R.framework/Resources/bin/exec

To see which versions you have available. With the 64 bit GUI from:

http://r.research.att.com

You will be running the 64-bit R binaries whenever you start the GUI. For R
on the command line, you can specify which version gets used by setting the
environment variable R_ARCH to either i386 or x86_64


iaw4 wrote:
 
 
 PPS: how do I learn which version of R is running?
 
 

Try sessioninfo()


Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Location-of-Packages--tp25438651p25438849.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] loading a package .Rda file at package load time

2009-09-14 Thread cls59



Hi, I have seen the answer to this sometime before but I just can't find it
again - pointers appreciated.

I have a package that contains some data.frames saved as .Rda files in the
data/ directory. When the package is loaded I would like to have them be
available in the workspace (without the user having to explicitly load them
using data(...)).

If my package does not use a NAMESPACE, I can place data(varName) in
.First.lib. However if I use NAMESPACES then the above line will fail when
placed in .onLoad. I was thinking of doing something such as
load'filename.Rda') but that would require me to know the path to the
package in a platform independent way.

Can anybody suggest how I can acheive this?

Thanks,

-- 
Rajarshi Guha

/quote

You mentioned that you used something similar to:

.First.lib - function( libname, pkgname ){

  data( varName )

}

And it didn't work when you attached a NAMESPACE to the package. If your
.Rda files are stored in the data directory of the package, have you tried
using:

.First.lib - function( libname, pkgname ){

  data( varName, package = pkgname )

}


If that doesn't work, then system.file() may be used to explicity recover
the location of your package data files:

.First.lib - function( libname, pkgname ){

  data( system.file( 'data/myDataFile.Rda', package = pkgname )

}

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/loading-a-package-.Rda-file-at-package-load-time-tp25439508p25441073.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Brand new To R

2009-09-13 Thread cls59



czarjosh wrote:
 
 I am trying to learn R right now.   I came from minitab and wanted to
 learn something a bit more robust.   I am trying to figure out some simple
 probability to measures but I do not know the commands.  I am using OSX. 
 Are there resources for figuring out simple events?
 

As David mentioned, the Introduction to R is a great place to start if you
have never used the language before. With OS X, you can find it under the
Help - R Help menu. Then click on the link for An Introduction to R.


czarjosh wrote:
 
 If I have data distributed as Normal(5,4) and I wanted to know what the
 probability of P(6) would be this, I cannot quite figute out how to work
 this out.
 

Functions for calculating probabilities and quantiles using distributions
are covered in Section 8 of the introduction document.

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Brand-new-To-R-tp25424799p25425997.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] making package interface with FORTRAN under windows

2009-09-13 Thread cls59



Carrie Li wrote:
 
 Dear r-help group,
 
   I am creating a package that has some FORTRAN code under windows. I have
 read through Writing R Extension but still not so clear about the steps.
 
 Before R CMD build, how can I create a dynamic library and later in my R
 function using dyn.load (xxx.dll) ?
 If I already have a .dll file, can I build the package with the dll file
 directly ?
 Does any one have any reference with the steps easier to follow ?
 
 Many thanks!
 
 Carrie
 
 


The easiest way to approach this is to leave the creation of the .dll to R.
This is done by storing your fortran source code inside a folder named 'src'
inside the R package. For example, say you have a package like the
following:

myPackage/
  DESCRIPTION
  R/
  man/
  src/

Placing a Fortran file, say mySubroutine.f90 inside the src/ folder will
cause R to automatically create and install myPackage.dll when the package
is built. The final step is to ensure R loads the dll when the library is
loaded. This is done by adding a file called zzz.R to the R/ folder which
contains the following function:

.onLoad -
function( libname, pkgname ){

  # You can put other package startup stuff in here as well.

  library.dynam( pkgname, pkgname, libname )

}

Now the rest of your package functions will be able to access the Fortran
routines in the dll through calls to .Fortran.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/making-package-interface-with-FORTRAN-under-windows-tp25425236p25426155.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Question about Factors

2009-09-13 Thread cls59



Chris Li wrote:
 
 Hi all,
 
 I am new to R and I have got a question in regards to factors.
 
 Say I have a simple dataset like the following:
 
 Name   Time Value
 a 1:00 1.25
 a 2:00 1.26
 b 1:00 1.29
 b 2:00 1.28
 c 1:00 1.21
 c 1:30 1.20
 c 2:00 1.23
 
 I want to write a script that automatically plot value against time for a,
 b and c. Because I have got more than 1 datasets, therefore the name of
 the next dataset may consist d, e, h and g. So I will need a script that
 can detect the changes in Name automatically.
 
 Thank you very much for your time.
 
 Chris
 


I'm assuming you want something like a separate scatter plot for each
level of Name-- i.e. for this example a plot of Value ~ Time for 'a', then
a new plot of Value ~ Time for 'b', ect.

One easy way to chop a data frame into a bunch of mini data frames based on
the value of a factor is the  by() function. For example, supposing your
data frame is named data, the following might produce what you want:

by( data, data[[ 'Name' ]], function(slice){

  # Slice is now a smaller data frame which contains only the
  # values which share a row with a one of the factor levels in Name

  dev.new()

  plot( Value ~ Time, data = slice,
main = paste('Scatter plot for', slice[[ 'Name' ]][1])
  )

})


Another way to easily create the same plots and visualize them all on one
page as a series of small multiples would be to use Hadley Wickham's ggplot2
package:

qplot( Value ~ Time, data = data ) + facet_wrap( ~ Name )


Hope some of this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Question-about-Factors-tp25428665p25429985.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] fitting nonlinear model

2009-09-09 Thread cls59



Bill Hyman wrote:
 
 My data look like:
 
 Np year
 962
 915
 897
 85   10
 
 

And which equation are you trying to fit to this data?

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/fitting-nonlinear-model-tp25370697p25371220.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] fitting nonlinear model

2009-09-09 Thread cls59



Bill Hyman wrote:
 
 Hi Milton,
 
 Thanks for your help. Actually, I would like to fit a non-linear fashion.
 For some data like below, 'lm' may not work very well. Do you have idea?
 Thanks again!
 
 

That's why information equation you are trying to fit is very important. For
example, the BOD data set in R is:

BOD
  Time demand
118.3
22   10.3
33   19.0
44   16.0
55   15.6
67   19.8

BOD demand can be modeled as a function of Time using the following
equation:

demand = BODu * ( 1 - exp( -K * Time ) )

Where BODu and K are the unknown parameters of the model. One way of doing a
non-linear fit in R is to use nls(), the nonlinear least-squares function:

model - nls( demand ~ BODu * ( 1 - exp( -K * Time ) ), 
data = BOD, 
start = list( BODu = max( BOD[['demand']]), k = 0.1 ) 
)

Note that with nls(), it is necessary to provide starting guesses for the
parameters as a list using the start parameters of the nls function.

Hope this helps!

-Charlie

P.S. 
Providing an example of the equation you are trying to fit to your data will
help us provide an answer that is more specific to your situation.


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/fitting-nonlinear-model-tp25370697p25371862.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] The code behind the function

2009-09-09 Thread cls59



Chunhao Tu wrote:
 
 Hi R users,
 I have a question. How can I see the code behind the function. For
 example,
 
 boxplot
 function (x, ...) 
 UseMethod(boxplot)
 environment: namespace:graphics
 
 I really would like to see how people code this. Could someone please show
 me how to see the code behind the function?
 Many Thanks
 Tu
 
 


When you type a function name and see something like:

UseMethod(boxplot)

This means the the function you are inquiring about is a generic function-
that is it examines the class of the object passed to it and then calls a
class function. These class functions, also known as methods, all have the
form:

boxplot.class-name

So, a quick way to see which methods may be available is to use the methods
function()

 methods( boxplot )
[1] boxplot.default  boxplot.formula* boxplot.matrix

This shows that there are visible methods for objects of class matrix and
stats and a default method that is used in all other cases. Sometimes there
may be other methods that have been hidden in away in package namespaces
where it is harder to find them as in the case of boxplot.formula.

For visible methods, simply type their name to see their contents. I suspect
you will be most interested in boxplot.default:

 boxplot.default
[output omitted]

For non-visible methods, like boxplot.formula, use the getAnywhere function:

 getAnywhere( 'boxplot.formula' )
[output ommitted]

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/The-code-behind-the-function-tp25370743p25372134.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Writing R Scripts and passing command line arguments

2009-09-07 Thread cls59


Abhishek Pratap wrote:
 
 
 1. What's the best way to pass command line arguments to R scripts ?
 
 

As Gabor mentioned, the commandArgs function and the getopt package provide
some excellent starting points for this.



Abhishek Pratap wrote:
 
 
 2. How to execute R scripts from command line ? When I use R CMD BATCH I
 see 
 no output on the screen 
 
 

I believe R CMD BATCH dumps all of it's output to a file ending in .Rout. If
you want more control over input and output to your script then Rscript is
the utility to use.


Abhishek Pratap wrote:
 
 
 3. What does R --slave --vanilla do  ?
 
 

If I recall correctly, --vanilla makes it so that R does not waste time
trying to load a previously saved session and also makes it so that R does
not try to save history and environment variables when it exits. Vanilla
also disables the loading of options from profile files such as ~/.Rprofile.

I think --slave makes R shut up about it's self and run more quietly than it
normally does.

Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Writing-R-Scripts-and-passing-command-line-arguments-tp25334067p25334648.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Why tempdir() always give me the same results in the same session?

2009-09-06 Thread cls59


Peng Yu wrote:
 
 
 tempdir() always gives me the same result. Should it give a different
 result each time I call it?
 
 

The help page for tempdir() contains the following explanation of the return
value:

?tempdir

...
For tempdir, the path of the per-session temporary directory. 


I would interpret that to mean that each time you start R a temporary
directory is assigned which retains a static value until you close R and
then open it again later. 

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Why-tempdir%28%29-always-give-me-the-same-results-in-the-same-session--tp25323681p25323805.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R to MATLAB translation

2009-08-10 Thread cls59


apjaworski wrote:
 
 Hi,
 
 Is there any package out there that might help me with translating R code 
 into MATLAB?  Using RSiteSearch I found a bunch of MATLAB stuff but it 
 all seems to go in the opposite direction, i.e., emulating MATLAB 
 functions in R.
 
 Thanks in advance,
 
 Andy
 


The biggest problem with translating R code to anything is that some sort of
parser must be written that can deconstruct a chunk of R code and the
reconstruct it in another language. Several attempts have been made at an R
to C translator but so far these have not gone very far. Given that the C
translation has stalled, it is unlikely that a translator for MATLAB exists.

Two approaches that you could take to this problem are:

1. Re-implement your R programs into MATLAB. This is how most of R's
emulated MATLAB functions came about.

2. Find some way of calling R from within MATLAB so that you don't have to
re-implement anything. A quick Google search turned up the following
windows-only interface:

http://www.mathworks.com/matlabcentral/fileexchange/5051

It appears to have good reviews.

Good luck!

-Charlie



-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/R-to-MATLAB-translation-tp24906288p24909382.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] create dataset permanently in package (i.e. default or our own package)

2009-07-27 Thread cls59


Albert EINstEIN wrote:
 
 Hi,
 actually while opening R console and R commander we see some packages like
 car and datasets. in this packages we have default datasets are available.
 example: women and prestige like that. now i created a sales dataset
 importing from excel, xml or text file. now i want to store that dataset
 permanently  in any one of the package like i mentioned above (car or
 datasets). now i closed my R session. after some time i opened R console
 and R commander. Now I will not create again sales dataset.While clicking
 any one of package that sales dataset should be found. 
 if possible please give me the code it will be very helpful for us.
 
 Thanks in advance.
 
 

The steps you need to follow are:

1. Open a new R session.

2. Create your 'sales' dataset and any other datasets you want to preserve.
Make sure these are the only objects in your workspace- i.e. they are the
only names that come up when you use ls().

3. Create a new package using package.skeleton('myPackage')

This will create a new folder called myPackage that contains a folder called
data. Inside data will be a .rda file for your sales dataset and any other
datasets you had in your environment at the time package.sekeleton was run.

Now you need to install your package. This can be done by:

system('R CMD INSTALL myPackage')

Or from the command line:

R CMD INSTALL myPackage

Note that if you are using Windows, you will need to install Duncan
Murdoch's Rtools package located at:

http://www.murdoch-sutherland.com/Rtools/

If the installer asks anything about modifying your PATH, allow it to do so.

Once the package has been installed, you can load your dataset using:

library(myPackage)
data(sales)

If you want to add additional data sets, save them to individual .rda files
using:

save('myFirstNewDataset',file='myFirstNewDataset.rda')
save('mySecondNewDataset',file='mySecondNewDataset.rda')

Then move the .rda files to the data folder inside the myPackage folder and
re-run R CMD INSTALL

Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/create-dataset-permanently-in-package-%28i.e.-default-or-our-own-package%29-tp24679076p24688214.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] storing output in html or pdf table format.

2009-07-27 Thread cls59


Albert EINstEIN wrote:
 
 Hi every one,
 Thanks for every one who are all supporting to us. we want some
 clarification on output in R. I have generated summary statistics output
 for dataset (E.g. sales) in output window. Now i want  to store that
 output in a html or pdf in a table format. if possible can any one provide
 code for this one.
 
 Thanks in advance.  
 
 

You might want to check out the xtable package:

install.packages('xtable')

The vignette contains some examples of what it can produce in a PDF file
through LaTeX. I believe the package also supports output to HTML tables:

vignette('xtableGallery')

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/storing-output-in-html-or-pdf-table-format.-tp24692508p24692850.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] moving text labels in plot

2009-07-26 Thread cls59



Luis Iván Ortiz Valencia wrote:
 
 Hi R users
 
 I need to specify some parameter input in plot code to move Y text label
 to
 left.
 
 plot(temp, develo_rate, xlab = expression(paste(Temperature (C^o,))),
 ylab = expression(paste(Development rate (d^-1,))),las=1,pch=19,
 xlim=c(0,32),ylim=c(0,0.03),xaxs = i, yaxs = i)
 
 Plot result is added.
 
 any help?
 
 Ivan
 
 


From the looks of your plot, the label is already to the left as far as it
can go. The problem is that the left margin of the plot is not big enough to
allow good separation between the axes label and the axes numbering.

You can adjust the plot margins by calling the par() function before
creating your plot. In this case you want to indicate that you are setting
the mar option and pass a vector of four numbers:

par( mar = c(bottom, left, top, right) )

Note that the defaults for mar are:

c( 5.1, 4.1, 4.1, 2.1 )


Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/moving-text-labels-in-plot-tp24668930p2467.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] how to avoid a for looping break after an error message

2009-07-25 Thread cls59



Victor Landeiro wrote:
 
 Hi all,
 I wrote a piece of code that generates simulated variables. after variable
 generation I use them in several analyzes.
 However, when I use a for to repeat the procedure 1000 times I get an erro
 message in one of the for steps, precisely at this time:
 gls.temp- gls(y2 ~ x2,correlation=corExp(form=~coord2[,1]+coord2[,2]))  #
 coord 2 are spatial coordinates
 and the error message is:
 Error in gls(y2 ~ x2, correlation = corExp(form = ~coord2[, 1] + coord2[,
 :  false convergence (8)
 I don´t know what causes this error. My problem is that this error stops
 all
 the calculations during the for looping and all previous results are lost.
 Can anyone help me to avoid that my looping stops after the error message?
 Thanks in advance,
 Victor Landeiro
 
 snip
 
 

You could wrap the offending function in the try statement:

gls.temp - try(  gls(y2 ~
x2,correlation=corExp(form=~coord2[,1]+coord2[,2]))  )

Then you want to check the class of gls.temp- if it is a try-error, the
data you are expecting will not be there:

if( class(gls.temp) == 'try-error' ){

  # You had an error, maybe just skip this iteration using next

}else{

  # It's all good- do your normal calculations  

}

Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/how-to-avoid-a-for-looping-break-after-an-error-message-tp24660446p24660575.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Include files?

2009-07-24 Thread cls59


Mark Knecht wrote:
 
 Hi,
I have 15 or 20 functions I've written to convert the sort of data
 I'm working with. They are currently in their own R file which I load
 by hand in Rgui before loading and running my main programs.
 
Is there any way to have this file included in my R program like
 #include might in C?
 
If not is there a simple newbie-type example of how to create a
 package so I could just say something like require(MWKFunctions) and
 be done with this?
 
 Thanks,
 Mark
 


If you are running a Unix based machine, rolling your own package is a snap.
Just load the R file containing your functions:

source('myFunctions.R')

Then use the package.skeleton to create an R package from the functions you
just loaded:

package.skeletion('myPackage')

package.skeleton will place just about every R object you currently have in
your environment into your package- this is a great way to save datasets
along with the functions you use to manipulate them.

Now comes the part that can be difficult on Windows. package.skeleton
created a directory called 'myPackage' that needs to be packed up into an
archive and then installed. This can be done from within R by the following
two commands (it may also be done directly from a command line, just execute
the commands inside the quotes ' ' ):

system( 'R CMD build myPackage' )
system( 'R CMD INSTALL myPackage' )

After that you can load up all your functions using:

library(myPackage)

After your package is loaded, if you had a data.frame or other variable
named myData when you created the package, you can load it up using:

data(myData)

The difficulties that arise on Windows are due to the poor state of the
Windows command line when it comes to the tools that are necessary to build
the package- most importantly you need a Perl interpreter.  Duncan Murdoch
has put together an installer that can supply the missing tools- you can
find it at:

http://www.murdoch-sutherland.com/Rtools/

If it asks anything about modifying your PATH while installing, allow it to
do so. Placing a folder of tools in the PATH makes the difference between
using

perl myScript.pl

or

/really/long/tiresome/hard/to/remember/path/to/perl myScript.pl



...or just using source works as well!  ;)

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Include-files--tp24647621p24648363.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] A Flash Mob for R Content on Stack Overflow: Tonite @ 7-9pm PST

2009-07-22 Thread cls59



Michael E. Driscoll wrote:
 
 R Users -
 
 Tomorrow night, we are leading a group of R programmers to a site
 called Stack Overflow, Stackoverflow is a collaborative question and
 answer site for programmers, currently lacks much R content.
 to populate some of the most oft-asked and reluctantly-answered
 questions about R.
 
 snip
 
 If you would like to join us in this effort, we'll be starting it 7pm
 PST Wednesday, July 22nd 2009.  You can see the questions as they
 appear on Stack Overflow or follow @rstatsmob on Twitter.
 
 

Excellent idea? I recently joint StackOverflow and have been very impressed
with the level of activity questions on that site receive. You are right
though- R is an extremely low profile language on the site. I'm glad you are
organizing this effort.

Let's go vote up some answers!

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/A-Flash-Mob-for-R-Content-on-Stack-Overflow%3A-Tonite-%40-7-9pm-PST-tp24602076p24602564.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] space in column name

2009-07-19 Thread cls59


Farrel Buchinsky-3 wrote:
 
 I read a table from Microsoft Access using RODBC. Some of the variables
 had
 a name with a space in it.
 R has no problem with it but I do.
 I cannot find out how to specify the space
 
 names(alltime)
  [1] IDLVL7  Ref Pv No Ref Pv Name   DOS
 Pt Last Name  Pt First Name MRN   CPT  
 CPT
 Desc  DxCd1 DxCd2 DxCd3 DxCd4
 [15] DOE
 
 But what do I do if I want to do something such as this
 alltime[grep(MIDDLE EAR EXPLORE,alltime$CPT Desc,]
 Error: unexpected symbol in alltime[grep(MIDDLE EAR EXPLORE,alltime$CPT
 Desc
 
 
 Farrel Buchinsky
 
 


The following might work:

alltime[grep(MIDDLE EAR EXPLORE,alltime[[ CPT Desc ]] ]

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/space-in-column-name-tp24559626p24559726.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] space in column name

2009-07-19 Thread cls59



cls59 wrote:
 
 


The following might work:

alltime[grep(MIDDLE EAR EXPLORE,alltime[[ CPT Desc ]] ]

-Charlie



ACK! Terribly sorry about the double post- but I forgot to close the quote.
It should be:

alltime[grep(MIDDLE EAR EXPLORE,alltime[[ CPT Desc ]] ]


Maybe I should wait until AFTER my morning coffee to browse R-help...

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/space-in-column-name-tp24559626p24559754.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] space in column name

2009-07-19 Thread cls59


Farrel Buchinsky-3 wrote:
 
 I sifted some more and read about a workaround for the problem. I could
 simply rename the columns so that there were no more spaces
 names(alltime) -gsub( ,., names(alltime))
 

That would certainly be a solution. The method I was trying to demonstrate
is that in addition  to using the $ sign syntax, lists and data.frames can
be accessed using strings- much like a hash. In order to do so, you must use
the [[]] or [] methods.

For example, just as you can do the following for a vector:

x - c(1,3,5)

for( i in 1:length(x) ){

  print( x[ i ] )

}

You could do something similar for your data.frame:

for( i in names(alltime) ){

 print( alltime[[ i ]] )

}

The important thing to note is that if you tried to use alltime$i in the
above loop, you would get a bunch of NULLS as there is no component named
'i'.

Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/space-in-column-name-tp24559626p24559869.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] how to run a R program with input arguments

2009-07-13 Thread cls59


edisonying wrote:
 
 I am a beginner in R and know only a little about it yet. I have a script
 written in R language, named as a.txt for example. I am using a Linux
 machine, at present I only know that I can type R in the terminal and
 then copy-paste the content in a.txt to the R's interface to execute the
 program. However, I want to know if there is any method that allows me to
 add some input arguments directly after the R in the terminal.
 Specifically, I want to type the following in the cmd line:
 
R (some flags or option) a.txt
 
 then the program will begin to run. Besides, if the program will read a
 data file first, can I also specify the data file in the command line?
 Then the complete command will become:
 
R  a.txt  data.txt
 
 This is important for a beginner. Thanks very much!:working:

 

We usually have R execute scripts in the following manner:

R --vanilla --slave --args [your args here]  scriptFile.R

Inside scriptFile.R the arguments can be retrieved by using
commandArgs(trailingOnly = T). The trailingOnly flag causes only the
arguments following --args to be be returned and not --args, --vanilla (no
save, no restore, quick startup) and --slave (makes R run quiet). 

Personally, I get tired of typing R --vanilla --slave --args all the time
and prefer to use Rscript. Since you are using Linux you can do the same by
putting the following hashbang at the top of your file:

#!/usr/bin/env Rscript

Then your script can be run using:

./scriptFile.R [your args here]

The arguments are still accessed inside the script using commandArgs(T)

Good luck!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/how-to-run-a-R-program-with-input-arguments-tp24465852p24471559.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Tex fonts in R plots

2009-07-09 Thread cls59


KARAVASILIS GEORGE wrote:
 
 Hello, R users.
 I would like to display the font of Math Mode of MikTex 2.3, WinEdt 5.4 
 in R plots, e.g. in xlab, ylab or legend.
 How can I do that?
 Thank you in advance.
 
 

A colleague and I have developed a package called pgfSweave that turns R
plots created inside a Sweave document into code that can be interpreted by
PGF/TikZ package for LaTeX. The end result of this process is that the text
in your figures are typeset with the same fonts used in the rest of your TeX
document.

The package can be found at: 

http://r-forge.r-project.org/projects/pgfsweave/
 
It has been used by the authors to typeset academic papers on windows and
produces good results. However we are still classifying it as an alpha
product because it has not been tested extensively.

Currently the underlying utility that translates R graphics into PGF form is
the java utility eps2pgf which may be found at:

http://sourceforge.net/projects/eps2pgf/

You may be interested in using this utility by it's self if you just want to
prep graphics for LaTeX and don't want to use Sweave. Simply create your
graphs in R using the eps() driver and process them using eps2pgf. 

eps2pgf has some drawbacks- it takes a few seconds to translate a graph and
certain R graphics commands, such as setting text size using cex, are not
respected.

Good luck!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Tex-fonts-in-R-plots-tp24382492p24414007.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] executing an error prone function without stopping a script

2009-07-09 Thread cls59



TU wrote:
 
 Dear R Users,
 
 I've used this a long time ago but have forgotten. Trawling aroung the
 various sources somehow does not lead me to it. How can I execute an error
 prone function without stopping a script if it goes wrong ?
 
 Thanks in advance,
 Tolga
 
 


See ?try

Basically, wrapping the function call in the try() function will make it so
that errors do not halt your script:

result - try( function( args ) )

You can then handle errors in your own way:

if( class(result) == 'try-error' ){
  # Error handling stuff.
}

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/executing-an-error-prone-function-without-stopping-a-script-tp24413760p24414337.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] productivity tools in R?

2009-07-03 Thread cls59


Duncan Murdoch-2 wrote:
 
 The Windows GUI was written before the Mac GUI, and was written using a 
 fairly strange toolkit, which are two reasons the Mac looks prettier. 
 But the Windows GUI has a few advantages over the Mac: 
 
 (snip)
 
   You can copy from the console, prompts and all, and paste just the 
 commands, to re-execute a sequence of commands.
 

I recently noticed that the Mac GUI contains a way to do block selection- so
you can select just the code you want to copy and exclude the prompts. Just
hold down the option key and the text cursor will turn into a crosshair
which allows you to exclude the prompt column while you select.

Even better, this behavior is somewhat universal as it works in other
applications such as the Terminal. I find it particularly useful for copying
code out of Vim without getting Vim's line numbers wrapped up in my
selections.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/productivity-tools-in-R--tp24293454p24326917.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] productivity tools in R?

2009-07-03 Thread cls59


Duncan Murdoch-2 wrote:
 
 
 cls59 wrote:
 
 I recently noticed that the Mac GUI contains a way to do block
 selection- so
 you can select just the code you want to copy and exclude the prompts.
 Just
 hold down the option key and the text cursor will turn into a crosshair
 which allows you to exclude the prompt column while you select.
 
 
 But doesn't that require you to edit out results?  The nice thing in the 
 Windows Rgui is that it does everything for you.  So I can take a block 
 of text like
 
   x - 1
   x
 [1] 1
   y - 2
   y
 [1] 2
   x + y
 [1] 3
 
 and cut and paste commands only to re-execute it, without manually 
 editing out the [1] 1, [1] 2, [1] 3 lines.  (Tony Plate contributed this 
 code way back in R 1.9.0; thanks Tony!)
 
 

You're right, with the Mac GUI one still has to copy blocks of code and
dodge around the output. Block selection only saves having to wipe out the
prompts on each line of a code block.


Duncan Murdoch-2 wrote:
 
 
 cls59 wrote:
 
 Even better, this behavior is somewhat universal as it works in other
 applications such as the Terminal. I find it particularly useful for
 copying
 code out of Vim without getting Vim's line numbers wrapped up in my
 selections.
 
 I think there's something of a culture clash here.  I consider it 
 torture to use an editor that does that.  Line numbers are part of the 
 frame around the text, they shouldn't be copied as part of the text.  (I 
 was going to say I'd never use such an editor, but that's not true: 
 sometimes I have no choice.)
 

As for the editor debate... 

I'm not touching that one with a ten hundred foot pole :p

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/productivity-tools-in-R--tp24293454p24327701.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] parallel R?

2009-06-26 Thread cls59


losemind wrote:
 
 
 Moreover, at my PC level, I have a 4-core PC, is there anything we
 could do in R to speed up my CV programs?
 
 

I have seen one very nice paper that compared parallelization options for R:

http://epub.ub.uni-muenchen.de/8991/



losemind wrote:
 
 
 we have to rewrite the whole R programs?
 
 

I would like to disclaim that I haven't had the time to parallelize any of
my R scripts. That being said, I noticed that many of the packages above
implement parallelized versions of the apply() functions. Maybe taking
advantage of apply wherever possible is a way to ensure you can get some
benefit from parallelization without rewriting large portions of code.

Hope this helps!

-Charlie





-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/parallel-R--tp24221547p24223277.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Partitioning matrix

2009-06-23 Thread cls59


Bogaso wrote:
 
 Let say, I have following matrix :
 
 dat - matrix(rnorm(40), 2, 20)
 
 Now I want to partition this like this :
 
 dat1 - dat[1,]
 dat2 - dat[2,]
 
 But point is that, dat1 and dat2 become vector object. How can I force
 them to be matrix object with dimension (1x20) ?
 
 

To turn a vector into a matrix or array set it's dimension attribute like
so:

dim(dat1) - c(1,20)
dim(dat2) - c(1,20)

Hope that helps!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Partitioning-matrix-tp24161021p24161038.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Calling Fortran from C++

2009-06-01 Thread cls59


Giura Gauss wrote:
 
 Hi,
 
 can anybody point me to a package with C++ code that call Fortran
 subroutines?
 
 I am trying to do the same thing but we scarce success.
 
 Error in dyn.load(utils.so) :
   unable to load shared library 'utils.so':
   dlopen(utils.so, 6): Symbol not found: _robcovf
   Referenced from: utils.so
   Expected in: dynamic lookup
 
 
 

It seems like you have a problem with function names which is a common
obstacle when interfacing C and Fortran. What usually happens is that a
trailing underscore gets added to fortran function names when they are
compiled. For example, consider a fortran subroutine declared as:

subroutine gaussQuad ( a, b, f1, f2 )

Since an underscore usually gets added and Fortran passes variables by
reference, the above subroutine would be seen by C as:

void gaussQuad_( a, b, f1, f2 );

Furthermore, in C++ I think you h$ave to wrap the prototype in an extern
statement:

extern C { void gaussQuad_(a, b, f1, f2 ); }

If you are running a unix system, you can check if your fortran function
names are receiving trailing underscores by running the nm utility on your
shared library. Ignore the leading underscores as they are expected by the C
compiler.

-Charlie




-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Calling-Fortran-from-C%2B%2B-tp23812140p23817336.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] What's a Data Frame?

2009-05-17 Thread cls59



prixel wrote:
 
  im completely confused. could someone please help.
 
 i have a series of data (0,0,0,0,1,1,0,0,0) and i need to create a data
 frame with it. but what is a data frame?
 
 thankyou :)
 

A data frame is similar to a matrix- however each column may be of a
different data type (character, number, logical, factor, ect.) and each
column has a name. Using the names a data frame may be manipulated as a
collection of vectors of the same length.

Look at ?data.frame for more information on data frames. The function
as.data.frame may be able to convert your data into a data frame object.

However, I cannot say if the object created by as.data.frame would satisfy
your needs without further manipulation since you did not specify why you
need a data frame. Are you calling some function that demands a data frame
as an input? If so, which function?

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/What%27s-a-Data-Frame--tp23580613p23586709.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] About the efficiency of R optimization function

2009-05-15 Thread cls59



popo UBC wrote:
 
 Hi Charlie,
 
 Thank you so much for suggestions!!
 
 Actually, I used the optimization toolbox in MABLAB before and I even
 wrote
 some numerical optimization programs by myself. As far as I know, some
 commercial optimization softwares had already replaced L-BFGS-B by more
 advanced algorithms, such as interior point method, SQP(sequential
 quadratic
 programming), implemented under trust region strategy. So,
 
- Have you ever tried these techniques? Are they available in R
 already?
- In your previous experieces, did R work satisfactory? I mean, was it
often that R failed to converge or spent too much time?
- Mainly, I need to calculate the MLE. But I really have no idea what
 the
likelihood may looks like. According to your experiences, would the
likelihood function be too complicated? Is L-BFGS-B good enough?
 
  Thanks again!!
 
 Popo
 
 

Hi Popo,

Truthfully, I do not have much direct experience with the R optim function.
For my linear optimization needs I usually use a package called HOPDM which
implements an interior point method. For nonlinear problems I use MINOS
which relies on conjugate gradients and interfaces nicely with the
simulation models I use in my field of study.

I have however taken a groundwater course where the class was assigned an
optimization problem concerning water supply. The objective function was
nonlinear and contained tens or hundreds of variables depending on the level
of discretization used in the numerical model. Some students used MINOS,
others used MATLAB and a few used R. All three packages generated similar
results.

If you are solving a maximum likelyhood problem, check out the mle function
in the stats4 package- it appears to be a front-end to optim which is
designed to tackle these sorts of problems. And, as I noted before, it is
possible to call a C or Fortran optimizer that you trust from within R.
Compared to my experience with MATLAB, calling an external Fortran routine
was an absolute walk in the park with R.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/About-the-efficiency-of-R-optimization-function-tp23552061p23568607.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Graphical output format

2009-05-15 Thread cls59



baptiste auguie-2 wrote:
 
 
 Just a thought:
 
 There was recently a discussion here on the pgfSweave [1] driver ---  
 it should be possible to use it in conjunction with XeTeX [2] to  
 process the pgf output. Presumably there will be issues of alignment  
 and spacing but at least arbitrary characters of most languages could  
 be employed in a fairly straight-forward manner.
 
 [1]: http://r-forge.r-project.org/R/?group_id=331
 [2]: http://www.tug.org/xetex/
 
 Regards,
 
 baptiste
 
 


The pgfSweave team is currently working on a native pgf graphics device for
R, hopefully it will be completed sometime during the summer. If you
experience any alignment/spacing issues using the current pgfSweave package,
please send an example to me and I will see if I can address these in the
new device.

I would prefer to receive example material and bug reports at the following
address:

sou...@sharpsteen.net

Thanks!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Graphical-output-format-tp23534288p23569046.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Centering R output in Sweave/LaTeX

2009-05-14 Thread cls59



Jean-Louis Abitbol-2 wrote:
 
 Good Day to All,
 
 When sweaving the following:
 
 \begin{table}
 \centering
 echo=FALSE=
 ftable(ifmtm$type, ifmtm$gender, ifmtm$marche , ifmtm$nfic,
 dnn=c(Type,Gender,Ambulant,Visit))
 @
 \caption{Four-way cross-tabulation on all data}
 \label{tab:crosstab}
 \end{table}
 
 the output of ftable is not centered while the latex caption is.
 
 Is there a way to center the R output in this setting ?
 
 Thanks for any help and best wishes, JL
 
 

I believe the problem arises because the R output is encased in fancyvrb
Verbatim environments after processing by Sweave. These environments have
implement their own justification rules which override the alignment
specified by \centering. A way to get around this would be to wrap the
output in another environment that does respect justification such as the
minipage:

\begin{table}
\centering

\begin{minipage}{0.5\textwidth}

echo=FALSE=
ftable(ifmtm$type, ifmtm$gender, ifmtm$marche , ifmtm$nfic,
dnn=c(Type,Gender,Ambulant,Visit))
@

\end{minipage}


\caption{Four-way cross-tabulation on all data}
\label{tab:crosstab}
\end{table}


You may have to adjust the width of the minipage in order to achieve the
results you desire. Hope this helps!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Centering-R-output-in-Sweave-LaTeX-tp23525507p23551392.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Sweave: Howto write real TeX formula in plot

2009-05-14 Thread cls59


Bugzilla from n...@jonasstein.de wrote:
 
 Thank you, Baptiste and Charlie.
 I found some examples wich look great on:
 http://www.texample.net/tikz/examples/
 

I'm glad you found Texample! It is an excellent site that shows many
practical, and beautiful, demonstrations of the types of figures that can be
constructed using LaTeX.
 


Bugzilla from n...@jonasstein.de wrote:
 
 
 I have installed pgf with apt-get install pgf. That worked fine, but
 installing pgfSweave fails.
 
 I did this:
 
 ,[ in R interpreter (running as root) ]
 | 
 | install.packages('pgfSweave',,'http://www.rforge.net/') 
 | 
 | Warning in install.packages(pgfSweave, , http://www.rforge.net/;) :
 |   argument 'lib' is missing: using '/usr/local/lib/R/site-library'
 | trying URL 'http://www.rforge.net/src/contrib/pgfSweave_0.7.1.tar.gz'
 | Content type 'application/x-tar' length 1017992 bytes (994 Kb)
 | opened URL
 | ==
 | downloaded 994 Kb
 | 
 | * Installing *source* package 'pgfSweave' ...
 | ** R
 | ** exec
 | ** inst
 | ** preparing package for lazy loading
 | Loading required package: stashR
 | Warning in library(pkg, character.only = TRUE, logical.return = TRUE,
 lib.loc = lib.loc) :
 |   there is no package called 'stashR'
 | Error: package 'stashR' could not be loaded
 | Execution halted
 | ERROR: lazy loading failed for package 'pgfSweave'
 | ** Removing '/usr/local/lib/R/site-library/pgfSweave'
 | 
 | The downloaded packages are in
 | /tmp/Rtmp6huu9t/downloaded_packages
 | Warning messages:
 | 1: In install.packages(pgfSweave, , http://www.rforge.net/;) :
 |   dependencies ‘stashR’, ‘filehash’, ‘digest’, ‘cacheSweave’ are not
 available
 | 2: In install.packages(pgfSweave, , http://www.rforge.net/;) :
 |   installation of package 'pgfSweave' had non-zero exit status
 |
 `
 
 what will i have to do now?
 
 


pgfSweave was created by modifying another package called cacheSweave.
cacheSweave uses the digest, filehash and stashR packages to store the
results of code chunk computations. If a code chunk for which caching has
been enabled is not changed between Sweave compilations pgfSweave and
cacheSweave load stored variable values from the cache files instead of
recomputing them. This hopefully saves time when all you want is to try out
a different figure header or placement, not redo a whole Monte Carlo
simulation.

The problem is that rforge.net, which hosts the pgfSweave project, does not
have these other packages. The easiest way around this is to install
cacheSweave from CRAN since the dependencies are the same:

install.packages('cacheSweave',dependencies=T)

Then install pgfSweave:

install.packages('pgfSweave',repos='http://www.rforge.net')



Bugzilla from n...@jonasstein.de wrote:
 
 
 And could someone give me an example how to write a formula in a plot?
 Like plot(... title=$\sigma^2 + \int x$)
 
 

The example you gave will work perfectly for inserting math into a plot
title when using pgfSweave. The only modification is that backslashes have
to be escaped so that they aren't interpreted by R as control characters.
For example, you will need to use \\sigma and \\int. For direct annotation
of a plot, you might consider the text() function which can be used to add
labels and formulae at any arbitrary location.

Good luck!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Sweave%3A-Howto-write-real-TeX-formula-in-plot-tp23127536p23551596.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] About the efficiency of R optimization function

2009-05-14 Thread cls59



popo UBC wrote:
 
 Hi all!
 
 The objective function I want to minimize contains about 10 to 20
 variables,
 maybe more in the future. I never solved such problems in R, so I had no
 idea about the efficiency of R's optimization functions. I know doing loop
 in R is quite slow, so I am not sure whether this shortage influences the
 speed of R's optimization functions.
 
 I would be very appreciated if anyone could share some experiences with
 me.
 The speed, stability of the R's optimization functions. Is it helpful to
 call a C/Fortran code to do the job, if possible.
 
 Many thanks in advance.
 
 Popo
 
 

Many functions available in R are implemented using a compiled language such
as C or Fortran- not the R language it's self. For example, the Source
section of the help page for optim states that the code for the Nelder-Mead,
BFGS and Conjugate Gradient methods were translated to C from Pascal and
then further optimized. The L-BFGS-B method appears to be implemented as
Fortran code.

Looking at the source of the optim function reveals that results are
computed by a call to .Internal(). Such calls usually indicate that R is
handing computations off to a compiled, rather than interpreted, routine.

If you have C or Fortran code you would prefer to use, take a look at the
help pages for .C() and .Fortran() as well as the Writing R Extensions
manual. The command line tool R CMD SHLIB will help you compile your code to
shared libraries that can be loaded by R using dyn.load().

-Charlie




-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/About-the-efficiency-of-R-optimization-function-tp23552061p23552668.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] I don't see libR.so in my installation directory

2009-05-09 Thread cls59



Tena Sakai wrote:
 
 
 
 I became aware of such as I was preparing for
 an installation of little r.  The installation
 material stated to look for libR.so, and I want
 to make sure that the one I installed (2.9.0)
 is used by little r.
 
 
 


little r... do you mean the scripting front end for R? If so, the core
utility Rscript is probably installed (it was added in 2.5.0 I believe) and
provides the functionality of little r, including hash-bang lines. Check the
bin folder in the R installation.

If you are talking about something different, ignore this message :)

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/I-don%27t-see-libR.so-in-my-installation-directory-tp23455074p23466363.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Seed of Random number generation

2009-05-01 Thread cls59


RON70 wrote:
 
 Dear all, is it possible to extract the seed that was used for some random
 number generation? For example suppose I draw a random sample of size 1000
 from a normal population :
 
 rnorm(1000)
 
 Now I want to know what seed R used for that sample generation. Any way
 out?
 
 Thanks and regards,
 

I believe R creates a random seed after a random number generation function
such as rnorm is called. The seed is stored in the vector .Random.seed  .
See ?RNG for more info on how to load, save and tweak the random seed.

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Seed-of-Random-number-generation-tp23342886p23342890.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Sweave: Howto write real TeX formula in plot

2009-04-19 Thread cls59


Bugzilla from n...@jonasstein.de wrote:
 
 Hi,
 
 i use Sweave to put plots in my .tex Documents. (pdflatex)
 Is there a nice solution for this:
 
 a) get a real LaTeX formula in the plot area. 
 I have only found very complicate solutions. Is there sth. like 
 \formula{x^2 = \oint f} 
 
 b) how can i format axis and legend to get exact the same font that is
 used in the TeX-document? 
 
 Thank you for any help. 
 
 


baptiste auguie-2 wrote:
 
 Perhaps try the pgfSweave package on r-forge?
 
 http://r-forge.r-project.org/projects/pgfsweave/
 
 HTH,
 
 baptiste
 
 

Aye- the aim of the pgfSweave package is to make the integration of R and
TeX more seamless. Right now it does a great job with respect to fonts by
passing the actual typesetting and printing of figures off to LaTeX. This is
accomplished using the java utility eps2pgf and requires the PGF/TiKZ
package for LaTeX:

http://sourceforge.net/projects/pgf/

The default behavior is to pass text directly to LaTeX unfiltered- this
means that things like percent signs and dollar signs will need to be
escaped by backslashes.

-Charlie



-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Sweave%3A-Howto-write-real-TeX-formula-in-plot-tp23127536p23130478.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] changing Swaeve output settings for .pdf and .eps - is there a way?

2009-04-17 Thread cls59


markheckmann wrote:
 
 
 The pdf() settings do not affect Sweave settings when producing a .pdf
 graphic. How can I change the Sweave default settings to e.g. 3 inch?
 
 

Try setting the width and height options in the figure chunk:

fig1,echo=F,plot=T,pdf=T,width=5,height=3
plot(1:10
@

To make a certain set of dimensions the defaults, use \SweaveOpts:

\SweaveOpts{width=5,height=3}

-Charlie



-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/changing-Swaeve-output-settings-for-.pdf-and-.eps---is-there-a-way--tp23078496p23091546.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] changing Swaeve output settings for .pdf and .eps - is there a way?

2009-04-17 Thread cls59



cameron.bracken wrote:
 
   I know the first time I set width=3 and the plot still spanned 80% of
 the page threw me off. 
 

I second this.

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/changing-Swaeve-output-settings-for-.pdf-and-.eps---is-there-a-way--tp23078496p23107772.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] using Sweave, how to save a plot in a given size

2009-04-15 Thread cls59


Lo_Lo wrote:
 
 
 I just want to add that I didn't have any overful box before I use :
 
 label=fig1, fig=FALSE, results = tex=
 pdf(fig1.pdf, 
 width = wid, heigth = hei)
 plot(1:10)
 plot(1:10)
 dev.off()
 cat(\\begin{figure}[h])
 cat(\\centering)
 cat(\\multido{\i=1+1}{7}{\includegraphics[page=\i,width=1.5in, height =
 1.5in]{images.pdf}}) 
 cat(\\end{figure})
 @
 

Here's a couple of pointers for using figures in Sweave that might help you
out.

1. Only one plot per figure chunk- Sweave gets confused if you use more than
one *high level* plotting command.

2. Don't call the pdf() function- the Sweave driver does this automatically
if you set pdf=T in the \SweaveOpts or the   code chunk header.

3. Don't use cat() to output the \begin{figure}, \end{figure},
\includegraphics, ect. These will end up in the wrong place.

From the look of your example, this is what you might want to include in
your .Rnw file:

\begin{figure}[h]
\centering

% Replace width and height with whatever dimensions you need. Leave them as
bare numbers
% i.e. 5 not 5in.
fig1,echo=F,fig=T,pdf=T,width=5,height=5=
plot(1:10)
@
% You can put a // here to cause the figures to separate onto two lines.
fig2,echo=F,fig=T,pdf=T,width=5,height=3=
plot(1:10)
@
% It is very important that all code chunks have different names! I.e.
fig1, fig2 ect.
\end{figure}

The result of running Sweave on filename.Rnw will be:

\begin{figure}[h]
\centering
\includegraphics{filename-fig1}
\includegraphics{filename-fig2}
\end{figure}

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/using-Sweave%2C-how-to-save-a-plot-in-a-given-size-tp23036715p23063594.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Compiling Fortran Subroutines as R Shared Objects on Mac OS-X

2009-04-15 Thread cls59



Chad R. Bhatti wrote:
 
 
 Hello,
 
 I am trying to compile some F77 subroutines as shared objects for R on my
 Mac.
 -- Mac OS-X Version 10.4.11 (Tiger Intel Mac)
 
 SNIP
 
 chad-r-bhattis-computer:~/MyR/Examples/Fortran/Test1 chadrbhatti$ R CMD
 SHLIB two.f
 gfortran -arch i386   -fPIC  -g -O2 -c two.f -o two.o
 gcc -arch i386 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names
 -mmacosx-version-min=10.4 -undefined dynamic_lookup -single_module
 -multiply_defined suppress -L/usr/local/lib -o two.so two.o  -lgfortran
 -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
 -Wl,CoreFoundation
 /usr/bin/libtool: for architecture cputype (16777223) cpusubtype (3)
 object: /usr/local/lib/libgfortran.dylib malformed object (unknown load
 command 4)
 /usr/bin/libtool: for architecture cputype (16777223) cpusubtype (3)
 object: /usr/local/lib/libgcc_s.10.4.dylib malformed object (unknown load
 command 4)
 make: *** [two.so] Error 1
 chad-r-bhattis-computer:~/MyR/Examples/Fortran/Test1 chadrbhatti$ which
 g77
 /usr/local/bin/g77
 chad-r-bhattis-computer:~/MyR/Examples/Fortran/Test1 chadrbhatti$ which
 gfortran/usr/local/bin/gfortran
 
 

Hi Chad,

I have an Intel mac running OS X 10.5 and I have compiled and used several
Fortran 77 and Fortran 90 subroutines, including MINPACK and MINOS, using R
CMD SHLIB.

I guess the first question I have, is have you installed the developer tools
from the OSX cd (the installer is located in the 'Optional Installs'
folder)? Pardon if this seems obvious, but it may explain the complaint
about the libgcc shared library.

Second, sometimes the options used in gfortran commands executed by R CMD
SHLIB can cause problems (specifically the -fPIC or -fno-common flags),
especially if modules or common blocks are involved in the fortran routines.
To get around this you can try running the compiler on the Fortran code
yourself and then R CMD SHLIB on the object code like so:

gfortran -c *.f
R CMD SHLIB -o myLib.so *.o

I'm no UNIX wizard myself, but the way you're trying to do things seems like
the correct way and should work, I have absolutely no idea why it is
complaining about cpu architecture if you have an Intel based machine.

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Compiling-Fortran-Subroutines-as-R-Shared-Objects-on-Mac-OS-X-tp23051543p23064039.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] I want to use Sweave, but only sometimes

2009-04-13 Thread cls59


Paul Johnson-11 wrote:
 
 Does anybody have a workable system to run an Rnw document through
 R-Sweave when necessary, but to just run it through LaTeX if no new R
 calculations are needed? I.e.,  the figures already exist, I do not
 need R to do more work for me, so I send the document straight to
 LaTeX.
 

The cacheSweave package does just that. A friend and I are also working on
another package called pgfSweave that incorporates code chunk caching along
with native compilation of R graphics output inside LaTeX so there are no
font differences. cacheSweave is available from CRAN and has been released
for a while now. Currently pgfSweave is only available from rforge.net and
is very much in beta. Hopefully things will really get moving this summer.

If you want to turn a .Rnw file into a plain LaTeX file, just run it through
Sweave('myPaper.Rnw') from the R command line. This creates myPaper.tex
which contains all the output and none of the  = @ chunk operators.

Also, your intuitions about the \SweaveOpts{prefix.string=figs/} command are
correct- this does specify a subfolder for figure output to reside in. Just
make sure you have created the folder yourself before running Sweave
otherwise it will give an error.

Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/I-want-to-use-Sweave%2C-but-only-sometimes-tp23026260p23031551.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Cross-platforms solution to export R graphs

2009-04-12 Thread cls59


Philippe Grosjean wrote:
 
 
 ..I would be happy to receive your comments and suggestions to improve 
 this document.
 All the best,
 
 PhG
 
 

LaTeX is my personal tool of choice and the vector format I use most often
is  http://sourceforge.net/projects/pgf/ PGF  (Portable Graphics Format),
implemented via a LaTeX package written by Till Tantu. There exists a very
nice converter called  http://sourceforge.net/projects/eps2pgf/ eps2pgf 
which is written in java and does an excellent job of translating R eps
output. The primary advantage of PGF is that figure text gets typeset by the
LaTeX engine instead of by R which unifies font choices and gives the final
document a very consistent, professional look. LaTeX commands, such as
mathematical typesetting, can also be embedded in the figure.

Along with a friend of mine, I have been working on a R package that extends
Sweave to include pgf graphics output. Currently 
http://www.rforge.net/pgfSweave pgfSweave  uses eps2pgf to perform the
conversions but a native R graphics device is planned to help speed up the
process. The package is currently very much a beta and has been developed
and tested on Mac OS X and runs quite well. Limited testing has been
conducted on Linux and Windows and we have produced documents on those
systems. Heavy development is expected to take place this summer.

PGF is a human-readable format and can be be easily annotated by adding
additional commands to the resulting file. However, editing the original
content is possible but difficult due to the lack of structure in the
eps2pgf output. The LaTeX environment can even be switched from pgfpicture
to tikzpicture which allows the use of TiKZ- a high level graphics language
built on top of PGF. TiKZ/PGF is easy to learn and the manual is one of the
best pieces of software documentation I have seen. 

Since I came across PGF a couple of years ago, Adobe Illustrator has
languished unused on my hard drive except for the occasional application of
Live Trace. An excellent showcase of PGF/TiKZ examples along with additional
tools is hosted at  http://www.texample.net Texample .

The end result of the PGF/TiKZ build process is a PDF which makes it very
portable.

All the best!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Cross-platforms-solution-to-export-R-graphs-tp22970668p23016682.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Sweave and backslashes

2009-02-05 Thread cls59

Hello Everyone,

I am an avid Sweave user and I am trying to pretty print floating point
numbers for latex output. For example in my document, I would like:

4.2\cdot 10^-{8}

Instead of:

4.2e-08

The Hmisc package has a nice function for doing this- but Hmisc has a ton of
dependencies and has proved very unportable to the various machines I work
on. So, I set out to write my own function that just uses basic R commands,
it looks like this:

latexNum - function (x,dig=4,sci=T) 
{
x - format(x,digits=dig,scientific=sci)

 x - gsub(e\\+00,,x)
 x - gsub(e\\-0([0-9]*),cdot 10^{-\\1},x)
 x - gsub(e\\-([0-9]*),cdot 10^{-\\1},x)
 x - gsub(e\\+0([0-9]*),cdot 10^{\\1},x)
 x - gsub(e\\+([0-9]*),cdot 10^{\\1},x)
 
return(x)
}

Everything works nicely, if I type

 latexNum(4*10^-3)

I get

[1] 4\\cdot10^{-3}

And the following:

 cat(latexNum(4*10^-3))

Produces:

4\cdot10^{-3}

However the following in a .Rnw file:

$\Sexpr{latexNum(4*10^-3)}$\\

Only produces this in the .tex output file:

$4cdot 10^{-3}$\\

No amount of extra backslashing seems to help. Any idea why my escapes are
not being respected?

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Sweave-and-backslashes-tp21864385p21864385.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Can R scripts executed in batch mode take a commandline argument?

2008-10-15 Thread cls59

On Unix/Linux platforms, you can use the included Rscript utility by adding
the following shebang at the top of your program. Command line arguments can
then be retrieved using the commandArgs function:

#!/usr/bin/Rscript

args - commandArgs(trailingOnly = TRUE)

args is now a character vector containing every space delimited text string
that followed your program name when you ran it. trailingOnly is set to TRUE
because the RScript interpreter prepends a few arguments of it's own that
you will probably have no use for.

As I stated earlier, this approach works great on Unix/Linux systems, I
havn't tested it in a Windows environment.

Good Luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Can-R-scripts-executed-in-batch-mode-take-a-commandline-argument--tp2914p20005573.html
Sent from the R help mailing list archive at Nabble.com.

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


  1   2   >