Re: [R] How to use Latex code in R loop?
On Sun, Apr 1, 2012 at 4:20 PM, Duncan Mackay mac...@northnet.com.au wrote: Hi There are a number of packages that produce latex from R, Sweave, brew, knitr - ones that come to mind. It happens that i use Sweave. The package you finally use may depend on your preferences The graphic output in R may also depend on what latex you use and other requirements - eg if you want to use it in a publication or share. Below is rather complex code from what I have done in the past in a loop and altered to give you an idea. It was done this way for a purpose as there may be better and more efficient ways to do it Basically : 1 The data is imported in a Sweave chunk 2 A tex file is created to add the figures in latex 3 A loop is created to print the graphs to go into latex and the latex code is added to the tex file for each graphic 4 the tex file is added to the sweave document as \input # import file data - read.table(x) # Create Latex file for figures and \input ftex - D:/Cic/Sweave/Sheep/AWTA/11/SheepWool-AWTA-Data11PRa.tex if (file.exists(ftex) ) file.remove(ftex) file.create(ftex) # open to append ff - file(ftex, a+) # Store macro text fchars - # Plot data ? pdf # numeric columns (not dates which are the first) for (j in c(0:2) ) { pdf(file = filename etc) print(graph eg xyplot) dev.off() # Comment if (j == 0 ){ fchars - paste(fchars, \\newpage\n\n, %**\n, % splom ofdaa2[,c(34:36)]|paste(FarmID,YearOfTesting), ex label{CWW.7.2.1}\n, sep = ) } ## j == 1 ** # R macro fchars - paste(fchars, \n, paste(%, yvar, \n, \\begin{landscape}\n), paste(\\begin{figure}\n\\centering\n), paste(\\includegraphics[height=0.88\\textheight,%\n, trim=0.5in 0.5in 0.5in 0.5in,%\n, keepaspectratio=true]%\n), paste( {, filename, }\n, sep = ), paste(\\pdfbookmark[3]{Pairs of , c(Hogget ,Ewe ,Wether )[(j+1)], yvar, }{, CWW.7.3., j, }\\label{, CWW.7.3., j, }\n, sep = ), paste(\\caption{, Pairs plot of , c(Hogget ,Ewe ,Wether )[(j+1)], yvar, against , \\textsf{YearOfTesting, FarmID}:\ , basenom, }\n, sep = ), paste(\\end{figure}\n\n, \\end{landscape}\n, \\clearpage\n\n, sep = ), sep = ) } ## for (j in seq_along(ysufbwo) ) # write % filename and close writeLines(fchars, ff) close(ff) FYI (and to advertise the R.rsp package), to avoid all that error-prone escape/cat/paste/file stuff, you can turn it all inside out by instead using the below file 'SheepWool-AWTA-Data11PRa.tex.rsp' and run R.rsp::rsp(SheepWool-AWTA-Data11PRa.tex.rsp) to generate the wanted SheepWool-AWTA-Data11PRa.tex and *.pdf image files. You could even use RSP directly on an Sweave file, e.g. 'report.Rnw.rsp' and generate the PDF via R.rsp::rsp(report.Rnw.rsp) - it will process RSP and the Sweave vignette automagically. See vignette 'Dynamic LaTeX reports with RSP' of R.rsp package for more details: http://cran.r-project.org/web/packages/R.rsp/ - - FILE START - - %% Filename: SheepWool-AWTA-Data11PRa.tex.rsp %% Usage: R.rsp::rsp(SheepWool-AWTA-Data11PRa.tex.rsp) %% Outputs: SheepWool-AWTA-Data11PRa.tex and *.pdf files. % # Change default output path for figures to current directory options(devEval/args/path=.) % % # import file data - read.table(x) % % for (j in 0:2) { % % if (j == 0) { % \newpage %** % splom ofdaa2[,c(34:36)]|paste(FarmID,YearOfTesting) ex label{CWW.7.2.1} % } # if (j == 0) % % %=yvar% \begin{landscape} \begin{figure} \centering \includegraphics[height=0.88\textheight,% trim=0.5in 0.5in 0.5in 0.5in,% keepaspectratio=true]% {%=toPDF(MyFigure, tags=j, aspectRatio=0.8, scale=1.3, { # Your R plot code here # print(graph eg xyplot) })%} \pdfbookmark[3]{Pairs of %=c(Hogget ,Ewe ,Wether )[(j+1)]%%=yvar%}{CWW.7.3.%=j%} \label{CWW.7.3.%=j%} \caption{Pairs plot of %=c(Hogget ,Ewe ,Wether )[(j+1)]%%=yvar% against \textsf{YearOfTesting, FarmID}: %=basenom%} \end{figure} \end{landscape} \clearpage % } # for (j in 0:2) % - - FILE END - - /Henrik REgards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email home: mac...@northnet.com.au At 00:48 2/04/2012, you wrote: Hi, I am newbie in Latex and R. I am working on one report in which i need to read file and display content of file by formatting (adding color boxes and colorful text for each record). For this i need to use latex code in R loop. How can i use Latex code in R loop. Any example will help me a lot.
Re: [R] unable to move temporary installation
My $.01 contribution without having read the complete thread: Some other process/service is locking your file/directory. There are a few Windows tools out there helping your to narrow down exactly which, e.g. http://www.guidingtech.com/10175/tools-to-delete-locked-files-in-windows/ /Henrik On Wed, Apr 4, 2012 at 10:07 AM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 03.04.2012 19:43, Drew Tyre wrote: A final followup. I have identified a rather extreme workaround. The problem arises when the function utils:::unpackPkgZip uses file.rename(...) to move the unzipped binary package from the temporary directory that it was unpacked into into the proper directory in the library tree. If one does debug(utils:::unpackPkgZip) and then steps through the function line by line, it works. Then check your virus scanner ot the speed of IO if this is a remote file system. Uwe Ligges Thank you. On Mon, Apr 2, 2012 at 12:06 PM, Drew Tyreaty...@unl.edu wrote: OK - so I followed the following steps, which I think rule out those causes 1) I uninstalled all remaining versions of R, and then deleted all the directories in c:\progra~1\R 2) I restarted the computer 3) I installed 2.14.2, and attempted to install the Rcmdr package. Same error message for both the cars package and the Rcmdr package. 4) I then exited and confirmed that I have write permission to C:\progra~1\R\R-2.14.2\libraries both by looking at the permissions, and by creating a directory in there. I appear to have full control, and I could create the directory. note that R is able to create the temporary directory to install the package, but not the correct, final directory. 5) I then uninstalled 2.14.2, and installed 2.15.0, hoping for a fix. No luck. Same error message. 6) I then tried installing the packages to a different directory, one that I created, c:\test, using install.packages(Rcmdr,c:\\test) This time, the car package installed correctly, but Rcmdr still had the same warning message Warning: unable to move temporary installation ‘c:\test\file136c67c337b3\Rcmdr’ to ‘c:\test\Rcmdr’ There is clearly something messed up on this computer, but I'm at a loss for how to get around it. Thanks for the suggestions, and I guess I have to work on a different computer! 2012/3/31 Uwe Liggeslig...@statistik.tu-dortmund.de On 31.03.2012 16:15, Drew Tyre wrote: Hi all, I'm having a strange error that prevents me from installing new packages, or updating packages after reinstalling. The error message is Warning: unable to move temporary installation ‘C:\Program Files\R\R-2.14.2\library\**file15045004ac2\sandwich’ to ‘C:\Program Files\R\R-2.14.2\library\**sandwich’ for one of the packages that is failing to install/update. This error started happening after I attempted installing lme4Eigen from the R-Forge repositories - that installation failed too. Any suggestions for fixes welcome. I don't want to upgrade to 2.15 just yet because I'm in the middle of a project (although if that's the solution I guess I'll have to do it). Probably the package is in use by another instance of R. Otherwise, check permissions. Best, Uwe Ligges R version 2.14.2 (2012-02-29) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.14.2 __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Drew Tyre School of Natural Resources University of Nebraska-Lincoln 416 Hardin Hall, East Campus 3310 Holdrege Street Lincoln, NE 68583-0974 phone: +1 402 472 4054 fax: +1 402 472 2946 email: aty...@unl.edu http://snr.unl.edu/tyre http://aminpractice.blogspot.com http://www.flickr.com/photos/atiretoo [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rgui maintains open file handles after Sweave error
See ?closeAllConnections Suggestion to the maintainer of Sweave: atomify the figure generation, e.g. use { pdf(); on.exit(dev.off()); {...}; } or similar, instead of { pdf(); {...}; dev.off(); } possibly by leaving a copy of the fault figure file for troubleshooting. /Henrik On Wed, Apr 4, 2012 at 12:25 PM, Alexander Shenkin ashen...@ufl.edu wrote: Hello Folks, When I run the document below through sweave, rgui.exe/rsession.exe leaves a file handle open to the sweave-001.pdf graphic (as verified by process explorer). Pdflatex.exe then crashes (with a Permission Denied error) because the graphic file is locked. This only seems to happen when there is an error in the sweave document. When there are no errors, no file handles are left open. However, once a file handle is stuck open, I can find no other way of closing it save for quitting out of R. Any help would be greatly appreciated! It would be nice to be able to write flawless sweave every time, but flawed as I am, I am having to restart R continuously. Thanks, Allie OS: Windows 7 Pro x64 SP1 sessionInfo() R version 2.14.2 (2012-02-29) Platform: i386-pc-mingw32/i386 (32-bit) test.Rnw: \documentclass{article} \title {file handle test} \author{test author} \usepackage{Sweave} \begin {document} \maketitle \SweaveOpts{prefix.string=sweave} \begin{figure} \begin{center} fig=TRUE, echo=FALSE= df = data.frame(a=rnorm(100), b=rnorm(100), group = c(g1, g2, g3, g4)) plot(df$a, df$y, foo) @ \caption{test figure one} \label{fig:one} \end{center} \end{figure} \end{document} Sweave command run: Sweave(test.Rnw, syntax=SweaveSyntaxNoweb) Sweave.sty: \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{Sweave}{} \RequirePackage{ifthen} \newboolean{Sweave@gin} \setboolean{Sweave@gin}{true} \newboolean{Sweave@ae} \setboolean{Sweave@ae}{true} \DeclareOption{nogin}{\setboolean{Sweave@gin}{false}} \DeclareOption{noae}{\setboolean{Sweave@ae}{false}} \ProcessOptions \RequirePackage{graphicx,fancyvrb} \IfFileExists{upquote.sty}{\RequirePackage{upquote}}{} \ifthenelse{\boolean{Sweave@gin}}{\setkeys{Gin}{width=0.8\textwidth}}{}% \ifthenelse{\boolean{Sweave@ae}}{% \RequirePackage[T1]{fontenc} \RequirePackage{ae} }{}% \DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl} \DefineVerbatimEnvironment{Soutput}{Verbatim}{} \DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl} \newenvironment{Schunk}{}{} \newcommand{\Sconcordance}[1]{% \ifx\pdfoutput\undefined% \csname newcount\endcsname\pdfoutput\fi% \ifcase\pdfoutput\special{#1}% \else\immediate\pdfobj{#1}\fi} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sincere inquiry about “subscript out of bounds” error in R
str() is your number one friend in R. Do str(A) and str(A2) after allocating the matrices and you'll be surprised. My $.02 /Henrik On Fri, Apr 6, 2012 at 7:35 AM, 卢永芳 sswwss...@126.com wrote: Hello,experts I am working on a simulation of effect of artificial selection on certain population in Animal Breeding.I am new beginner in coding. I have already build a matrix A(500*500) based on this code A-matrix(,500,500) for(i in 1:500){ for(j in 1:500){ ifelse(i==j,A[i,j]-1,A[i,j]-0) } } and I need to caculate A2 base on A and X1(4500*4500).Here are the codes A2-matrix(4500,500) for(i in 1:4500){ for(j in 1:500){ A2[i,j]-(A[X1[i,2],j]+A[X1[i,3],j])/2 } } and error happened like this:Error in A2[i, j] - (A[X1[i, 2], j] + A[X1[i, 3], j])/2 : subscript out of bounds I check the criculation number in for loop and it is perfect match with the dimension of matrix A and X1. I do not know how this error happened? And anther inportant question is that how can I build a matrix with very larger dimension which can not allocate in R.Error in matrix(, 45500, 45500) : cannot allocate vector of length 207025 I am looking forward to hear from you Kindest Regards [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] assigment operator question
On Sat, Apr 7, 2012 at 1:30 PM, Mark Heckmann mark.heckm...@gmx.de wrote: Hello, using the - assignment operator I do not understand why the following does not work. l - list() l list() l$arg1 - test error in l$arg1 - test : Objekt 'l' not found ?- says: The operators - and - cause a search to made through the environment for an existing definition of the variable being assigned. If such a variable is found (and its binding is not locked) then its value is redefined, otherwise assignment takes place in the global environment. Still I do noch understand why the above does not work. The object l is in the global environment. Can someone explain it to me? Yes, the object 'l' is in the global environment, but 'l$arg1' is not, cf. exists(l$arg1) and exists(l). Instead, this works: l - list(); l$args1 - test; but much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much better, do NOT use - (or assign()/get()) unless you fully understand what you're doing and have a very good reason for doing it, and that reason should be able pass the embarrassment-test on public R mailing lists. Got the point? Don't use it - there is another way to do what you want to achieve - you just have to ask/find out how. /H Thanks --Mark Mark Heckmann Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] assigment operator question
On Sat, Apr 7, 2012 at 2:01 PM, Mark Heckmann mark.heckm...@gmx.de wrote: Thanks! I'll try to stick to that advice! Maybe there is a better way... Here is what I want: I want to save some default settings for a package. The user can change these using a function similar to par(). I do not want to use options() here as it will be quite a lot of parameters. I was thinking about an invisible object in the global environment and using - or assign() to change the settings... What other roads are there to go? It sounds like you have a use case where using a global variable is acceptable, however options() is indeed a good alternative to host your settings. I'm not sure why you don't want to leverage the options() functionality that is already in place? Is it because you don't want to clutter up the options() output? You can always keep all of your package's setting in a single entry, e.g. options(myPkgOpts=myPkgOpts) where myPkgOpts is a list/tree (e.g. your 'l' below). Then you can have your own wrapper functions for settings and getting these options. The advantage with this approach is that the settings will sustain any attempts of cleaning up the global environment, e.g. rm(list=ls(all.names=TRUE)). FYI, this updated topic may be better suited for the R-devel list. /Henrik TIA --Mark Am 07.04.2012 um 22:51 schrieb Henrik Bengtsson: On Sat, Apr 7, 2012 at 1:30 PM, Mark Heckmann mark.heckm...@gmx.de wrote: Hello, using the - assignment operator I do not understand why the following does not work. l - list() l list() l$arg1 - test error in l$arg1 - test : Objekt 'l' not found ?- says: The operators - and - cause a search to made through the environment for an existing definition of the variable being assigned. If such a variable is found (and its binding is not locked) then its value is redefined, otherwise assignment takes place in the global environment. Still I do noch understand why the above does not work. The object l is in the global environment. Can someone explain it to me? Yes, the object 'l' is in the global environment, but 'l$arg1' is not, cf. exists(l$arg1) and exists(l). Instead, this works: l - list(); l$args1 - test; but much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much much better, do NOT use - (or assign()/get()) unless you fully understand what you're doing and have a very good reason for doing it, and that reason should be able pass the embarrassment-test on public R mailing lists. Got the point? Don't use it - there is another way to do what you want to achieve - you just have to ask/find out how. /H Thanks --Mark 末末 Mark Heckmann Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.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. 末末 Mark Heckmann Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Time out for a R Function
See also R help thread 'Wait for keystroke or timeout': http://www.mail-archive.com/r-help@r-project.org/msg97742.html /H On Mon, Dec 6, 2010 at 9:11 PM, Michael Bedward michael.bedw...@gmail.com wrote: Below is a toy function with one way of doing it. There are bound to be better ways :) function(niter = 10, time.out = 3) { pretend.task - function() { Sys.sleep(0.5) } start - proc.time() for (iter in 1:niter) { pretend.task() cur - proc.time() - start if (cur[3] time.out) return(timed out) } return(completed) } On 7 December 2010 13:04, Santosh Srinivas santosh.srini...@gmail.com wrote: Hello Group, I have an R-function that works fine for most part but sometime runs into a long loop! (I'm lazy and short on time to debug right now so want to do something easy) For my purpose, it is ok to make few errors is there a way I can put a timeout on a function and the r-process needes to move on to the next step? Thank you. S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
First, subset 'test' once, e.g. testT - test[1:3]; and then use sapply() on that, e.g. val - sapply(testT, FUN=function (x) { x$a }) Then you can avoid one level of function calls, by val - sapply(testT, FUN=[[, a) Second, there is some overhead in [[, $ etc. You can use .subset2() to avoid this, e.g. val - sapply(testT, FUN=.subset2, a) Third, it may be that using sapply() to structure you results is a bit overkill. If you know that the 'a' element is always of the same dimension, you can do it yourself, e.g. val - lapply(testT, FUN=.subset2, a) val - unlist(val, use.names=FALSE) # use.names=FALSE is much faster than TRUE See what that does /Henrik On Tue, Dec 7, 2010 at 6:47 AM, Alexander Senger sen...@physik.hu-berlin.de wrote: Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] Thank you for your advice Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tiff compression bug
Hi On Wed, Dec 8, 2010 at 11:18 PM, Ganqiang Liu g@imb.uq.edu.au wrote: Is there a bug in tiff compression output in Mac version? My program is correct when I run on windows version; However, in Mac, the compression fail~ Friendly and constructive sarcasm follows: Talking cars, your question translates to: My Mazda doesn't work. My Volvo works fine. Is there a problem with all Mazdas in the world? At least model and year of you Mazda and a detailed description of the problem would help narrow down the problem and identify the cause. Talking R, that last request translates to: Please provide sessionInfo() [includes R version and OS details] and a piece of reproducible R code that others [that also have Mazdas] can test. If there is something else needed to see the bug, that's useful too. My $.02 /Henrik In [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Time out for a R Function
FYI, I've added evalWithTimeout() to R.utils v1.6.0 (now on CRAN). It utilizes the built-in setTimeLimit() feature of R. You can either have it throw an error, which you then have to catch, or you can have it just give a warning that your evaluation timed out and then silently continue. From example(evalWithTimeout): # - - - - - - - - - - - - - - - - - - - - - - - - - # Function that takes a long time to run # - - - - - - - - - - - - - - - - - - - - - - - - - foo - function() { print(Tic); for (kk in 1:100) { print(kk); Sys.sleep(0.1); } print(Tac); } # - - - - - - - - - - - - - - - - - - - - - - - - - # Evaluate code, if it takes too long, generate # a timeout by throwing a TimeoutException. # - - - - - - - - - - - - - - - - - - - - - - - - - res - NULL; tryCatch({ res - evalWithTimeout({ foo(); }, timeout=1.08); }, TimeoutException=function(ex) { cat(Timeout. Skipping.\n); }) # - - - - - - - - - - - - - - - - - - - - - - - - - # Evaluate code, if it takes too long, generate # a timeout returning NULL and generate a warning. # - - - - - - - - - - - - - - - - - - - - - - - - - res - evalWithTimeout({ foo(); }, timeout=1.08, onTimeout=warning); See if that helps /Henrik On Wed, Dec 8, 2010 at 7:14 AM, Santosh Srinivas santosh.srini...@gmail.com wrote: Thank you. I tried this but not sure if I have implemented this correctly ... basically if function1 hangs .. I need the timeout to be triggered and then the process moves to the next function call. I have this: function1 - function(x){ setTimeLimit(elapsed = 5*60, transient = FALSE) step 1 step 2 step 3 } #Code to execute about function repeatedly. It moves to a new input variable when I call it back through a parameter repeat{ function1(x) } -Original Message- From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk] Sent: 07 December 2010 13:23 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Time out for a R Function On Tue, 7 Dec 2010, Santosh Srinivas wrote: Hello Group, I have an R-function that works fine for most part but sometime runs into a long loop! (I'm lazy and short on time to debug right now so want to do something easy) For my purpose, it is ok to make few errors is there a way I can put a timeout on a function and the r-process needes to move on to the next step? See the help on setTimeLimit(transient = FALSE) . Unlike other suggestions, that does not need you to change the code to check the time. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R.matlab memory use
Hi, I am using Octave; what does that save options do, more specifically, is compression taking place when saving that file? If compression is done, then the Rcompression package is utilized by R.matlab (otherwise not). BTW, you don't have to load Rcompression explicitly; R.matlab will do it for you if needed. So, if you start a fresh R session and load R.matlab and then try to load your package, is Rcompression loaded? If so, what version Rcompression do you have installed, i.e. what does sessionInfo() report afterward? Duncan TL did Rcompression updates addressing memory usage about a year ago (I think) and it might be that you are using an older version of it. You should also update R.matlab et al, because your using old versions (though I don't think that is the cause here). If Rcompression is the cause here, then it also make sense that you don't experience the memory hog when reading a text file (which is never compressed). You could also see if there is an option in Octave that safes to binary format but without compression. I know Matlab has such options. /Henrik (author of R.matlab) On Mon, Dec 20, 2010 at 7:11 AM, Stefano Ghirlanda dr.ghirla...@gmail.com wrote: Hi Ben, Thanks for your reply. My data structure is about 2 x 2000 so one order of magnitude the one you tried. I have no problem saving and reading smaller data structures (even large ones, just not his large) between octave and R using octave's save -7 (which saves MATLAB v5 files) and R.matlab's readMat. And I can save in text format in octave and read in R using read.octave (from package foreign) so it's not a big deal. I was just surprised that R.matlab needed more memory than I have (I have 3GB on this machine). Thanks, Stefano On Sun, Dec 19, 2010 at 10:54 PM, Ben Bolker bbol...@gmail.com wrote: Stefano Ghirlanda dr.ghirlanda at gmail.com writes: I am trying to load into R a MATLAB format file (actually, as saved by octave). The file is about 300kB but R complains with a memory allocation error: library(Rcompression) library(R.matlab) Loading required package: R.oo Loading required package: R.methodsS3 R.methodsS3 v1.2.0 (2010-03-13) successfully loaded. See ?R.methodsS3 for help. R.oo v1.7.2 (2010-04-13) successfully loaded. See ?R.oo for help. R.matlab v1.3.1 (2010-04-20) successfully loaded. See ?R.matlab for help. f - readMat(freq.mat) Error: cannot allocate vector of size 296.5 Mb On the other hand, if I save the same data in ascii format (from octave: save -text), resulting in a 75MB file, then I can load it without problems with the read.octave() function from package foreign. Is this a known issue or am I doing something wrong? My R version is: This is not a package I'm particularly familiar with, but: what commands did you use to save the file in octave? Based on 'help save' I think that 'save' by default would get you an octave format file ... you might have to do some careful reading in ?readMat (in R) and 'help save' (in octave) to figure out the correspondence between octave/MATLAB and R/MATLAB. If possible, try saving a small file and see if it works; if you still don't know what's going on, post that file somewhere for people to try. I was able to save -6 save.mat in octave and readMat(save.mat) in R successfully, saving a vector of integers from 1 to 1 million (which took about 7.7 Mb) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Stefano Ghirlanda www.intercult.su.se/~stefano - drghirlanda.wordpress.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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.matlab memory use
On Tue, Dec 21, 2010 at 10:15 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I am using Octave; what does that save options do, more specifically, is compression taking place when saving that file? That should be: I am [not] using Octave... /H If compression is done, then the Rcompression package is utilized by R.matlab (otherwise not). BTW, you don't have to load Rcompression explicitly; R.matlab will do it for you if needed. So, if you start a fresh R session and load R.matlab and then try to load your package, is Rcompression loaded? If so, what version Rcompression do you have installed, i.e. what does sessionInfo() report afterward? Duncan TL did Rcompression updates addressing memory usage about a year ago (I think) and it might be that you are using an older version of it. You should also update R.matlab et al, because your using old versions (though I don't think that is the cause here). If Rcompression is the cause here, then it also make sense that you don't experience the memory hog when reading a text file (which is never compressed). You could also see if there is an option in Octave that safes to binary format but without compression. I know Matlab has such options. /Henrik (author of R.matlab) On Mon, Dec 20, 2010 at 7:11 AM, Stefano Ghirlanda dr.ghirla...@gmail.com wrote: Hi Ben, Thanks for your reply. My data structure is about 2 x 2000 so one order of magnitude the one you tried. I have no problem saving and reading smaller data structures (even large ones, just not his large) between octave and R using octave's save -7 (which saves MATLAB v5 files) and R.matlab's readMat. And I can save in text format in octave and read in R using read.octave (from package foreign) so it's not a big deal. I was just surprised that R.matlab needed more memory than I have (I have 3GB on this machine). Thanks, Stefano On Sun, Dec 19, 2010 at 10:54 PM, Ben Bolker bbol...@gmail.com wrote: Stefano Ghirlanda dr.ghirlanda at gmail.com writes: I am trying to load into R a MATLAB format file (actually, as saved by octave). The file is about 300kB but R complains with a memory allocation error: library(Rcompression) library(R.matlab) Loading required package: R.oo Loading required package: R.methodsS3 R.methodsS3 v1.2.0 (2010-03-13) successfully loaded. See ?R.methodsS3 for help. R.oo v1.7.2 (2010-04-13) successfully loaded. See ?R.oo for help. R.matlab v1.3.1 (2010-04-20) successfully loaded. See ?R.matlab for help. f - readMat(freq.mat) Error: cannot allocate vector of size 296.5 Mb On the other hand, if I save the same data in ascii format (from octave: save -text), resulting in a 75MB file, then I can load it without problems with the read.octave() function from package foreign. Is this a known issue or am I doing something wrong? My R version is: This is not a package I'm particularly familiar with, but: what commands did you use to save the file in octave? Based on 'help save' I think that 'save' by default would get you an octave format file ... you might have to do some careful reading in ?readMat (in R) and 'help save' (in octave) to figure out the correspondence between octave/MATLAB and R/MATLAB. If possible, try saving a small file and see if it works; if you still don't know what's going on, post that file somewhere for people to try. I was able to save -6 save.mat in octave and readMat(save.mat) in R successfully, saving a vector of integers from 1 to 1 million (which took about 7.7 Mb) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Stefano Ghirlanda www.intercult.su.se/~stefano - drghirlanda.wordpress.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Setting bioconductor repository in .Rprofile. Is there a permanent way?
It is easier than that. Use http://www.bioconductor.org/packages/release/bioc or http://www.bioconductor.org/packages/devel/bioc /Henrik On Mon, Jan 24, 2011 at 10:56 AM, Martin Morgan mtmor...@fhcrc.org wrote: On 01/24/2011 10:45 AM, Kevin Wright wrote: I currently set the Bioconductor repository in my .Rprofile using this code (which needs editing for every version number change of Bioconductor): # Choose repositories repos - structure(c(CRAN=http://streaming.stat.iastate.edu/CRAN;, CRANextra=http://www.stats.ox.ac.uk/pub/RWin;, BioCsoft=http://www.bioconductor.org/packages/2.7/bioc;, Rforge=http://r-forge.r-project.org;)) options(repos=repos) rm(repos) I'd like to avoid editing the version number. One hack to do so is this code that adds all repositories. setRepositories(ind=1:10) r - getOption(repos) r - r[!is.na(r)] options(repos=r) Is there a simpler way? I've searched for quite a while without finding an answer. Incidentally, the help page for options says: A Bioconductor mirror can be selected by setting options(BioC_mirror): the default value is http://www.bioconductor.org;. The word default is a bit confusing here, because when I start R, I see: one possibility is to source('http://bioconductor.org/biocLite.R') in .Rprofile, after which biocinstallRepos() provides the correct bioc repositories for the version of R in use; it does clutter the .GlobalEnv a little and would be irritating if, e.g., on a laptop, internet access were slow or not reliable. For the latter I wrote makeActiveBinding(biocLite, local({ env - new.env() function() { if (!exists(biocLite, envir=env, inherits=FALSE)) { evalq(source(http://bioconductor.org/biocLite.R;, local=TRUE), env) } env[[biocLite]] } }), .GlobalEnv) which doesn't make the connection until one accesses the biocLite variable. Martin R options()$BioC_mirror NULL -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] building a subscript programatically
2011/11/1 Ernest Adrogué nfdi...@gmail.com: Hi, On ocasion, you need to subscript an array that has an arbitrary (ie. not known in advance) number of dimensions. How do you deal with these situations? It appears that it is not possible use a list as an index, for instance this fails: x - array(NA, c(2,2,2)) x[list(TRUE,TRUE,2)] Error in x[list(TRUE, TRUE, 2)] : invalid subscript type 'list' The only way I know is using do.call() but it's rather ugly. There must be a better way!! do.call('[', c(list(x), TRUE, TRUE, 2)) [,1] [,2] [1,] NA NA [2,] NA NA Any idea? library(R.utils) x - array(1:8, dim=c(2,2,2)) x , , 1 [,1] [,2] [1,]13 [2,]24 , , 2 [,1] [,2] [1,]57 [2,]68 extract(x, 3=2) , , 1 [,1] [,2] [1,]57 [2,]68 For more details/examples, see help(extract.array, package=R.utils). It doesn't to assignments, but could be achieved by: idxs - array(seq(along=x), dim=dim(x)) idxs - extract(idxs, 3=2) x[idxs] - ... base::arrayInd() may also be useful. /Henrik Regards, Ernest __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] download.file
See downloadFile() of the R.utils package (on CRAN); it allows you to download to a file to a given path (without have to replicate the filename), and it also have an option (the default) to drop zero-size files that are (sometimes) created when download.file() tries to download a non-existing file. Moreover, the method downloads files in binary mode by default (download in text mode is a common cause for corrupt files). See help(downloadFile, package=R.utils) for more bells and whistles. /Henrik On Tue, Nov 8, 2011 at 3:32 PM, Mary Kindall mary.kind...@gmail.com wrote: I am downloading say 100 files from ucsc website and storing it into dest folder. download.file function create a file in destination folder even if the file is not present which is something I dont want. So I wrote if condition to remove the file if the download function has non zero value. Now it exits when there is an error or file not present. How can I use try and if condition together so that the program does not exit on error and delete the created file in destination folder. for (i in 1: 100) { fileUrl = ucscfilenames[i] if (download.file(fileUrl, destFile, 'wget' , quiet = TRUE) != 0) { file.remove(destFile) } } thanks -- - Mary Kindall Yorktown Heights, NY USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R v2.13.2 - Cannot find Rcmd on path?
FYI, you can use tools such as Path Manager 1.1.1 (GPL) on Windows: http://www.softpedia.com/get/System/System-Miscellaneous/Path-Manager.shtml to list, modify (add, remove, reorder, remove duplicates, normalize) your PATH environment variable. For each directory it identifies in PATH it will also let you know whether it is valid or not and list files that exist in that directory, iff valid. So, if you don't see Rcmd.exe where you expect it to be, you know you did something wrong when setting PATH. My $.02 /Henrik On Sun, Nov 13, 2011 at 9:50 PM, Yihui Xie x...@yihui.name wrote: Well, I just mean to give the user an option during installation -- like you did in Rtools. I have decided not to argue on this issue any more. Thanks a lot anyway! Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Sun, Nov 13, 2011 at 4:20 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 11-11-13 1:15 PM, Yihui Xie wrote: I remember I was torn into pieces a few months back when I made a wishlist here that R adds its bin path to PATH on Windows during installation. People had tons of reasons of objection. Although I do not use these batchfiles (usually I do not actually use Windows), I see there is a motivation behind them: there needs to be an easy way for Windows users to use R in command line (e.g. R CMD build...). You may argue that it is easy to understand PATH and modify it manually, and I will say nothing but thank Windows again. Sorry this seems to be off-topic. I don't remember any rending and tearing, but I do remember objections to modifying the path during installation. I wouldn't want to write code to do that, because it's hard: - Most people don't want to put R first, because it may hide something important. - Putting it last won't work if an earlier version is already there. So you need to examine the path and correct it, an automatic change is unlikely to be successful. But if you want to write code to do that, just go ahead and do it. Put it in a package, even. Duncan Murdoch Regards, Yihui -- Yihui Xiexieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] unable to get R CMD to work as expected on a 64 bit windows machine
See if Rcmd check --help works. I've always been use that form (I'm on Win7 64-bit). /Henrik On Mon, Nov 14, 2011 at 9:06 AM, Martyn Byng martyn.b...@nag.co.uk wrote: Hi Josh, Thanks for that, which directory needs to be in the path? There is a file called R.exe in C:\Program Files\R\R-2.14.0\bin C:\Program Files\R\R-2.14.0\bin\x64 and C:\Program Files\R\R-2.14.0\bin\i386 I currently have C:\Program Files\R\R-2.14.0\bin\x64 in the path (which is, I'm guessing why R CMD --help works), do I need the others in the path as well, and if so, in what order? Cheers Martyn -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: 14 November 2011 16:57 To: Martyn Byng Cc: r-help@r-project.org Subject: Re: [R] unable to get R CMD to work as expected on a 64 bit windows machine Hi Martyn, My guess is that you need to add the directory where R is located to your Windows PATH variable. It sounds like Windows just doesn't know where to find R. HTH, Josh On Mon, Nov 14, 2011 at 8:48 AM, Martyn Byng martyn.b...@nag.co.uk wrote: Hi, I've just downloaded and installed R 2.14.0 using the windows binary on a 64bit windows machine running windows 7. Rterm / RGui work as expected, as does R CMD --help and R CMD BATCH --help however R CMD check --help returns no information and I seem to be unable to check a package. Various other options also seem to not be working as expected, i.e. R CMD REMOVE aa (where aa is just a garbage name) appears to do nothing (whereas the same command on a 32bit windows machine returns with a message that package aa does not exist.) Just invoking R on the command line appears to do nothing on 64 bit windows as opposed to starting a command line version of R (ala Rterm) on 32 bit windows. Any pointers as to what I've done wrong during the installation would be appreciated. Cheers Martyn sessionInfo() R version 2.14.0 (2011-10-31) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. Th...{{dropped:4}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ This e-mail has been scanned for all viruses by Star. The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Putting directory path as a parameter
file.path() is much better for this than paste(), e.g. dir - C:/Users/Desktop pathname - file.path(dir, bs_dev_segment_file.csv) temp_data - read.csv(pathname) /Henrik On Tue, Nov 15, 2011 at 10:08 AM, R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com wrote: Try pasting them together like paste(dir, ...) You may need to use the collapse argument. Alternatively, change your working directory to dir with setwd(). M On Nov 15, 2011, at 9:12 AM, aajit75 aaji...@yahoo.co.in wrote: Hi List, I am new to R, this may be simple. I want to store directory path as parameter which in turn to be used while reading and writing data from csv files. How I can use dir defined in the below mentioned example while reading the csv file. Example: dir - C:/Users/Desktop #location of file temp_data - read.csv(dir/bs_dev_segment_file.csv) If I run this it will show errors: Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'dir/bs_dev_segment_file.csv': No such file or directory Regards, -Ajit -- View this message in context: http://r.789695.n4.nabble.com/Putting-directory-path-as-a-parameter-tp4043092p4043092.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Event handling in R
...because you're catching the timeout error with try() so it has not effect, and hence the while(TRUE) {} loop keeps running. Without knowing anything about graphics event handlers per se, here's an alternative to catch the timeout event: library(R.utils); plot(0, 0); eventEnv - getGraphicsEventEnv(); setGraphicsEventHandlers(prompt='Test'); q - NULL; evalWithTimeout({ q - getGraphicsEvent(); }, timeout=1); print(q); does it. See print(evalWithTimeout) to see what you are doing differently. My $.02 /Henrik On Thu, Dec 15, 2011 at 9:49 PM, beetonn nicholas.bee...@utas.edu.au wrote: Dear R-helpers, I've just started playing with getGraphicsEvent() in R, and was wondering if there is a simple way to stop this function waiting for input after a pre-defined time, instead of relying either on a non-NULL value from one of the event handlers or for a user-interrupt for it to halt (as per the R manual). The only way that I've thought of to make this work is using setTimeLimit to kill the function after a set time - here's a (messy) example: setTimeLimit(cpu = 1) plot(0, 0) eventEnv - getGraphicsEventEnv() setGraphicsEventHandlers(prompt = 'Test') while(TRUE) { err - try(q - getGraphicsEvent(), silent=TRUE) print(err) } # Not run setTimeLimit(cpu = Inf) but setTimeLimit doesn't seem to kill getGraphicsEvent() properly, as running this code just ends up with the repeated returned error of Error in getGraphicsEvent(): recursive use of getGraphicsEvent not supported instead of the intended Error: reached CPU time limit every second. Is there a way to get around this problem, or a different method to make this work? Or should I quit dabbling in things beyond my ken? Thanks, Nick __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Event handling in R
Hi. On Wed, Dec 21, 2011 at 4:20 AM, beetonn nicholas.bee...@utas.edu.au wrote: Thanks, Henrik! That's given me some food for thought, and evalWithTimeout certainly seems to be a nicer way of doing this than setTimeLimit. I should probably explain a little more clearly: I want to stop getGraphicsEvent() without stopping the program flow (assume we're running the code from a source file) - hence the error catching in my example. If we allow the exception through, it stops the program (which I don't want) but stops getGraphicsEvent() properly, meaning we can run it again (which I do want). If we don't, the exception is caught and getGraphicsEvent() keeps running - meaning we can't run it again without it throwing a recursion error. To illustrate, if we set up with: library(R.utils) plot(0) eventEnv - getGraphicsEventEnv() setGraphicsEventHandlers(prompt = 'Test') and then while (TRUE) evalWithTimeout( {out - getGraphicsEvent();}, timeout=1, onTimeout=error) it crashes out of the loop with a time-out error. If we instead use while (TRUE) evalWithTimeout( {out - getGraphicsEvent();}, timeout=1, onTimeout=ignore) it throws a recursion error after running getGraphicsEvent() for the second time. Ok, I see, so this issue has nothing to do with the timeout per se. It looks as if the sanity checks of the internal getGraphicsEvent() code believes getGraphicsEvent() was called from one of the event functions (e.g. onKeybd), which is not the case. Looking at the internal code: do_getGraphicsEvent(SEXP call, SEXP op, SEXP args, SEXP env) { ... if (dd-gettingEvent) error(_(recursive use of getGraphicsEvent not supported)); ... } It seems that 'gettingEvent' is not reset to FALSE in case of a timeout - only if a graphics event occurs (or something like that). I don't know if there is a way to reset it manually. I've cc:ed Duncan Murdoch, who I believe wrote these handlers. By the way, I may have found a bug in evalWithTimeout - there is a line else if (onTimeout == silent) { but silent is not one of the allowed arguments to the function. I changed this to ignore and it seemed to work fine. Thanks for pointing this out. In the next release (R.utils v1.9.7), onTimeout=silent will be one to use. (The term ignore is a bit ambiguous). /Henrik Cheers, Nick ...because you're catching the timeout error with try() so it has not effect, and hence the while(TRUE) {} loop keeps running. Without knowing anything about graphics event handlers per se, here's an alternative to catch the timeout event: library(R.utils); plot(0, 0); eventEnv - getGraphicsEventEnv(); setGraphicsEventHandlers(prompt='Test'); q - NULL; evalWithTimeout({ q - getGraphicsEvent(); }, timeout=1); print(q); does it. See print(evalWithTimeout) to see what you are doing differently. My $.02 /Henrik On Thu, Dec 15, 2011 at 9:49 PM, beetonn wrote: Dear R-helpers, I've just started playing with getGraphicsEvent() in R, and was wondering if there is a simple way to stop this function waiting for input after a pre-defined time, instead of relying either on a non-NULL value from one of the event handlers or for a user-interrupt for it to halt (as per the R manual). The only way that I've thought of to make this work is using setTimeLimit to kill the function after a set time - here's a (messy) example: setTimeLimit(cpu = 1) plot(0, 0) eventEnv - getGraphicsEventEnv() setGraphicsEventHandlers(prompt = 'Test') while(TRUE) { err - try(q - getGraphicsEvent(), silent=TRUE) print(err) } # Not run setTimeLimit(cpu = Inf) but setTimeLimit doesn't seem to kill getGraphicsEvent() properly, as running this code just ends up with the repeated returned error of Error in getGraphicsEvent(): recursive use of getGraphicsEvent not supported instead of the intended Error: reached CPU time limit every second. Is there a way to get around this problem, or a different method to make this work? Or should I quit dabbling in things beyond my ken? Thanks, Nick __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Indexing multi-dimensional table
On Thu, Dec 22, 2011 at 4:34 AM, David A Vavra dava...@verizon.net wrote: I want to take slices of a multi-dimensional table (or array) without knowing the number of dimensions in advance. As a test I tried using (in this example a 3d table): do.call(`[`, list(tbl, x,NULL,NULL)] where I built the list on the fly. It works great as long as I only want the first dimension however when I try a different dimension, say with list(tbl,NULL,x,NULL), I get 0 x 0 matrix as the result. I thought this was because I wasn't calling the right function but there is no `[.table` or `[.matrix` or even `[.array`. Am I going about this the wrong way? From help([, package=base): An index value of NULL is treated as if it were integer(0).. y - array(1:24, dim=c(2,3,4)) dimnames(y)[[1]] - sprintf(a%d, 1:dim(y)[1]) dimnames(y)[[2]] - sprintf(b%d, 1:dim(y)[2]) dimnames(y)[[3]] - sprintf(c%d, 1:dim(y)[3]) y[NULL,2:3,1,drop=FALSE] , , c1 b2 b3 y[integer(0),2:3,1,drop=FALSE] , , c1 b2 b3 I don't think there is an easy way to achieve: y[,2:3,1,drop=FALSE] , , c1 b2 b3 a1 3 5 a2 4 6 using do.call([) without explicitly specify the indices for that missing dimension, i.e. y[seq(length=dim(y)[1]),2:3,1,drop=FALSE] , , c1 b2 b3 a1 3 5 a2 4 6 If you're willing to use R.utils you can do: library(R.utils); extract(y, indices=list(2:3,1), dims=c(2,3), drop=TRUE); b2 b3 a1 3 5 a2 4 6 My $.02 /Henrik DAV [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] is there an equivalent for #ifdef (C langage) in R
You could generate an R script using an RSP template 'main.R.rsp' containing: % DEBUG - TRUE % % if (!DEBUG) { % make_addition = function(a, b) { % } % % if (DEBUG) { % a = 1 b = 2 % } % c=a+b plot(c) % if (!DEBUG) { % return(c) } % } % which you can compile into 'main.R' using R.rsp::rsp(main.R.rsp). You can compile and run it in one go by: source(R.rsp::rsp(main.R.rsp)) Changing DEBUG to FALSE generates the alternative main.R file. Note that the *.R.rsp file is not parsed by R, so it is only the generated main.R that has to be valid before it is passed to source(). My $.02 /Henrik On Thu, Jan 12, 2012 at 7:36 AM, ikuzar raz...@hotmail.fr wrote: Hi, I'd like to know if there is an equivalent for #ifdef (Clangage) in R. I 'd like to do something like: useDebug = defmacro(DEBUG, expr=(DEBUG==1)) if(useDebug(0)){ #Here I do not use debug mode make_addition = function(a, b) { c=a+b plot(c) return(c) } }else{ #here I use debug mode c=a+b } I assume this would work... The problem is : if I have 15 lines of code in if{ } bloc I have to copy and paste these15 lines into else{} bloc. These is too many lines in my file... Is there something like (in C langage): #define DEBUG 1 #ifndef DEBUG make_addition = function(a, b) { #endif #ifdef DEBUG a = 1 b = 2 #endif c=a+b plot(c) #ifndef DEBUG return(c) } #endif my goal is to run my program WITHOUT calling my_addition(1, 2) (for debugging). The main problem : all variables do not exist when just running my _file.R , I have to call my_function if I want to see results. I use RStudio Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/is-there-an-equivalent-for-ifdef-C-langage-in-R-tp4289356p4289356.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Virus Infection in colorspace_1.1-1.zip (R x64 2.14.1)
[R] False Virus detection with colorspace package? [Tue Nov 8 00:44:37 CET 2011] https://stat.ethz.ch/pipermail/r-help/2011-November/294875.html /H On Tue, Jan 24, 2012 at 11:46 AM, Stephen P Molnar s.mol...@sbcglobal.net wrote: I keep finding the Win32\Huer virus in colorspace_1.1-1.zip for R x64 2.14.1 running MS Windows 7. As a result I am not able to use rattle or ChemometricsWithR. I have tried several different mirrors with the same result. Fortunately AVG has caught and quarantined the problem, but the colorspace package is not available. I can use the package on my Linux OS, but, of course, Linux isn't bothered by viruses. I'm posting this to the list as I am not sure just what to do with the information. Stephen P. Molnar, Ph.D. Life is a fuzzy set Foundation for Chemistry Stochastic and multivariate http://www.FoundationForChemistry.com (614)312-7528 (c) Skype: smolnar1 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] replacing characters in matrix. substitute, delayedAssign, huh?
The quick solution: parseAndEval - function(x, ...) eval(parse(text=x)) apply(BM, MARGIN=c(1,2), FUN=parseAndEval) My $.02 /Henrik On Mon, Jan 30, 2012 at 10:26 AM, Paul Johnson pauljoh...@gmail.com wrote: A user question today has me stumped. Can you advise me, please? User wants a matrix that has some numbers, some variables, possibly even some function names. So that has to be a character matrix. Consider: BM - matrix(0.1, 5, 5) Use data.entry(BM) or similar to set some to more abstract values. BM[3,1] - a BM[4,2] - b BM[5,2] - b BM[5,3] - d BM var1 var2 var3 var4 var5 [1,] 0.1 0.1 0.1 0.1 0.1 [2,] 0.1 0.1 0.1 0.1 0.1 [3,] a 0.1 0.1 0.1 0.1 [4,] 0.1 b 0.1 0.1 0.1 [5,] 0.1 b d 0.1 0.1 Later on, user code will set values, e.g., a - rnorm(1) b - 17 d - 4 Now, push those into BM, convert whole thing to numeric newBM - apply(BM, c(1,2), as.numeric) and use newBM for some big calculation. Then re-set new values for a, b, d, do the same over again. I've been trying lots of variations on parse, substitute, and eval. The most interesting function I learned about this morning was delayedAssign. If I had only to work with one scalar, it does what I want delayedAssign(a, whatA) whatA - 91 a [1] 91 I can't see how to make that work in the matrix context, though. Got ideas? pj sessionInfo() R version 2.14.1 (2011-12-22) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.14.1 -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to unzip files in R
I may be wrong, but I don't think unz() handles bz2 files - only zip files. See bunzip2() of the R.utils package (which utilizes bzfile connections). /Henrik On Tue, Jan 31, 2012 at 2:34 PM, ql16717 ql16...@gmail.com wrote: Hi, I have downloaded a bunch of bz2 files. I wonder if R will be able to unzip them in a batch mode or even one at a time? I was looking at the unz function. But it didn't work well. Say I have a bz2 file in H:/Temp/65502805_532.pair.bz2. Anyone has any suggestion? thanks John setwd(H:\\Temp\\) getwd() [1] H:/Temp fn-list.files(pattern=bz2, full.names=TRUE) fn [1] ./65502805_532.pair.bz2 unz(description=fn, filename=65502805_532.pair, open=r) Error in unz(description = fn, filename = 65502805_532.pair, open = r) : cannot open the connection In addition: Warning message: In unz(description = fn, filename = 65502805_532.pair, open = r) : cannot open zip file './65502805_532.pair.bz2' sessionInfo() R version 2.14.0 (2011-10-31) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] pdInfoBuilder_1.18.0 oligo_1.18.1 oligoClasses_1.16.0 affxparser_1.26.2 RSQLite_0.10.0 [6] DBI_0.2-5 Biobase_2.12.1 loaded via a namespace (and not attached): [1] affyio_1.22.0 Biostrings_2.22.0 bit_1.1-8 ff_2.2-4 IRanges_1.12.1 [6] preprocessCore_1.16.0 splines_2.14.0 tools_2.14.0 zlibbioc_1.0.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] passing an extra argument to an S3 generic
For these type of setups, I typically turn to default values, e.g. hatvalues.mlm - function(model, m=1, infl=NULL, ...) { if (is.null(infl)) { infl - mlm.influence(model, m=m, do.coef=FALSE); } hat - infl$H m - infl$m names(hat) - if(m==1) infl$subsets else apply(infl$subsets,1, paste, collapse=',') hat } So people may prefer to do the following: hatvalues.mlm - function(model, m=1, infl, ...) { if (missing(infl)) { infl - mlm.influence(model, m=m, do.coef=FALSE); } hat - infl$H m - infl$m names(hat) - if(m==1) infl$subsets else apply(infl$subsets,1, paste, collapse=',') hat } The downside with this approach is that args(fcn) doesn't reveal the default behavior; instead you need to document it clearly in the help(fcn). My $.02 /H On Fri, Feb 10, 2012 at 12:13 PM, Michael Friendly frien...@yorku.ca wrote: On 2/9/2012 6:24 PM, ilai wrote: You do not provide mlm.influence() so your code can't be reproduced. Or did you mean to put lm.influence() in the formals to your hatvalues.mlm ? If yes, then 1) you have a typo 2) lm.influence doesn't allow you to pass on arguments, maybe try influence.lm instead. No, I've written an S3 method, influence.mlm and a computational method, mlm.influence, both of which take an m= argument. I didn't post all the code because I thought the question might have an easy answer based on what I provided. I include all the code and a test case in the attached .txt file that can be sourced. -Michael Elai On Thu, Feb 9, 2012 at 1:42 PM, Michael Friendlyfrien...@yorku.ca wrote: I'm trying to write some functions extending influence measures to multivariate linear models and also allow subsets of size m=1 to be considered for deletion diagnostics. I'd like these to work roughly parallel to those functions for the univariate lm where only single case deletion (m=1) diagnostics are considered. Corresponding to stats::hatvalues.lm, the S3 method for class lm objects, hatvalues-function (model, ...) UseMethod(hatvalues) hatvalues.lm- function (model, infl = lm.influence(model, do.coef = FALSE), ...) { hat- infl$hat names(hat)- names(infl$wt.res) hat } I have, for class mlm objects hatvalues.mlm- function(model, m=1, infl=mlm.influence(model, m=m, do.coef = FALSE), ...) { hat- infl$H m- infl$m names(hat)- if(m==1) infl$subsets else apply(infl$subsets,1, paste, collapse=',') hat } where mlm.influence() does the calculations, but also allows the m= argument to specify subset size. Yet when I test this I can't seem to pass the m= argument directly, so that it gets stuffed in to the infl= call to mlm.influence. # fit an mlm library(heplots) Rohwer2- subset(Rohwer, subset=group==2) rownames(Rohwer2)- 1:nrow(Rohwer2) Rohwer.mod- lm(cbind(SAT, PPVT, Raven) ~ n+s+ns+na+ss, data=Rohwer2) class(Rohwer.mod) [1] mlm lm ## this doesn't work, as I would like it to, calling the hatvalues.mlm method, but passing m=2: hatvalues(Rohwer.mod, m=2) Error in UseMethod(hatvalues) : no applicable method for 'hatvalues' applied to an object of class c('double', 'numeric') I don't understand why this doesn't just call hatvalues.mlm, since Rohwer.mod is of class mlm. # These work -- calling hatvalues.mlm explicitly, or passing the infl= argument with the call to # mlm.influence hatvalues.mlm(Rohwer.mod, m=2) hatvalues(Rohwer.mod, infl=mlm.influence(Rohwer.mod,m=2)) Can someone help me understand what is wrong and how to make the .mlm method allow m= to be passed directly to the infl= computation? thx, -Michael -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] If (x 0)
Try adding --vanilla when calling R, e.g. R --vanilla --no-save --args 5 test1.R because I think you're picking up and previously stored session. You'll most likely will find that res - conditional1(x) will give an error saying 'conditional1' is not defined; you need to define the function before using it. My $.02 /H On Mon, Feb 13, 2012 at 1:59 PM, Schmidt, Michael mschm...@med.miami.edu wrote: Hi, I am new to R. I was trying to get a very simple program to run. Take one number from the command line. If the number 0 return -1. If number 0 return 1 and if the number == 0 return 0. The code is in a file called test1.R The code: #useage: R --no-save --args 5 test1.R args = (commandArgs(TRUE)) x = as.numeric(args[1]) print(x) res - conditional1(x) cat(result= ,res,\n) conditional1 - function(x){ result - 0 if (x 0) { result - 1 } else if (x 0) { result - -1 } return(result) } The output: R --no-save --slave --args 1 test1.R [1] 1 result= 1 R --no-save --slave --args -1 test1.R [1] -1 result= -1 ] R --no-save --slave --args 0 test1.R [1] 0 result= -1 The problem: For arguments 1 and -1 it works as intended. For 0 (zero) it does not. If the 0 value is passed into the function named conditional1 I would expect both if-statements to evaluate to false and 0 being return. From what I can tell (0 0) evaluates to true since -1 is returned. Hm... What is going on? What am I doing wrong? Why is this happening? I am baffled! Any help would be appreciated. Thanks Mike [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Powerful PC to run R
On Sun, May 15, 2011 at 9:31 AM, Spencer Graves spencer.gra...@structuremonitoring.com wrote: Also: A previous post in this tread suggested Rprof [sec. 3.2 in Writing R Extensions, available via help.start()]. This should identify the functions that consume the most time. The standard procedure to improve speed is as follows: 1. Experiment with different ways of computing the same thing in R. In many cases, this can help you reduce the compute time by a factor of 10 or even 1,000 or more. Try this, perhaps using proc.time and system.time with portions of your code, the rerun Rprof. I second this one; if you have things running for weeks, and you haven't done any serious optimization already, you most likely can bring that down to days or hours by investigating where the bottlenecks are. Here is a good illustration how a simple piece of R code is made 12,000 times faster: http://rwiki.sciviews.org/doku.php?id=tips:programming:code_optim2 2. After you feel you have done the best you can with R, you might try coding the most compute intensive portion of the algorithm in a compiled language like C, C++ or Fortran. Then rerun Rprof, etc. 3. After trying (or not) compiled code, it may be appropriate to consider CRAN Task View: High-Performance and Parallel Computing with R. (From a CRAN mirror, select Task Views - HighPerformanceComputing: High-Performance and Parallel Computing with R.) You may also want to try the foreach package from Revolution Computing (revolutionanalytics.com). These capabilities can help you get the most out of a multi-core computer. NOTE: While your code is running, you can check the Performance tab in Windows Task Manager to see what percent of your CPUs and physical memory you are using. I mention this, because without foreach you might get at most 1 of your 4 CPUs running R. With foreach, you might be able to get all of them working for you. Then after you have done this and satisfied yourself that you've done the best you can with all of this, I suggest you try the Amazon Cloud. If you have not already solved your problem with this and have not yet tried these three steps, I suggest you try this. It may take more of your time, but you will likely learn much that will help you in the future as well as help you make a better choice of a new computer if you ultimately decide to do that. Hope this helps. Spencer On 5/15/2011 8:28 AM, Gabor Grothendieck wrote: On Fri, May 13, 2011 at 6:38 AM, Michael Haenlein haenl...@escpeurope.eu wrote: I'm currently running R on my laptop -- a Lenovo Thinkpad X201 (Intel Core i7 CPU, M620, 2.67 Ghz, 8 GB RAM). The problem is that some of my calculations run for several days sometimes even weeks (mainly simulations over a large parameter space). Depending on the external conditions, my laptop sometimes shuts down due to overheating. If you are on Windows press the Windows key and type in Power Options. When the associated dialog pops up choose Power Saver. Now your PC will use less power so it won't heat up so much although your performance could suffer a bit. Also ensure that there is sufficient air circulation around the machine. To move this hardware-specific discussion off the R-help list, I strongly recommend the 'Thinkpad.com Support Community' (open community/non-Lenovo) with lots of experts and users: http://forum.thinkpads.com/ I've seen discussions on overheating/emergency shutdowns there. /Henrik -- Spencer Graves, PE, PhD President and Chief Operating Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R Style Guide -- Was Post-hoc tests in MASS using glm.nb
On Wed, May 18, 2011 at 6:28 PM, David Scott d.sc...@auckland.ac.nz wrote: Another style guide is at: http://www1.maths.lth.se/help/R/RCC/ Listed as a first draft and dated 2005, but still worth a read. Has some references also. That URL obsolete (I need to have it removed) - a more recent/stable URL is [5] below. LIST OF CONVENTIONS/STYLES FOR R: [1] R coding standards in the R Internals manual http://www.cran.r-project.org/doc/manuals/R-ints.html#R-coding-standards [2] Bioconductor coding standards http://wiki.fhcrc.org/bioc/Coding_Standards [3] Google R style [http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html] [4] R style guide by Hadley Wickham (based on [3]) http://had.co.nz/stat405/resources/r-style-guide.html [5] R Coding Conventions (RCC) - a draft by Henrik Bengtsson http://aroma-project.org/developers/RCC [6] The Aroma R Coding Conventions (Aroma RCC) by Henrik Bengtsson (based on [5]) http://aroma-project.org/developers/AromaRCC Note that there are often different objectives driving the different coding styles, which is why it makes little sense to debate certain items. As an example, one convention may favor portability to another language limiting it to not use S4 (just an example). /Henrik I think I recall Hadley having a style guide which he requested his students followed, but I didn't like it too much (sorry Hadley) . I am with Bill that style guides should be consulted and their recommendations considered, but it is personal preference as to which rules one accepts. I don't find it objectionable if someone has written in a style I don't particularly like, but it is objectionable if no thought has been given to programming style. David Scott On 19/05/11 10:26, bill.venab...@csiro.au wrote: Hi Bert, I think people should know about the Google Sytle Guide for R because, as I said, it represents a thoughtful contribution to the debate. Most of its advice is very good (meaning I agree with it!) but some is a bit too much (for example, the blanket advice never to use S4 classes and methods - that's just resisting progress, in my view). The advice on using- for the (normal) assingment operator rather than = is also good advice, (according to me), but people who have to program in both C and R about equally often may find it a bit tedious. We can argue over that one. I suggest it has a place in the R FAQ but with a suitable warning that this is just one view, albeit a thougtful one. I don't think it need be included in the posting guide, though. It would take away some of the fun. :-) Bill Venables. -Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: Wednesday, 18 May 2011 11:47 PM To: Venables, Bill (CMIS, Dutton Park) Cc: r-help@r-project.org Subject: R Style Guide -- Was Post-hoc tests in MASS using glm.nb Thanks Bill. Do you and others think that a link to this guide (or another)should be included in the Posting Guide and/or R FAQ? -- Bert On Tue, May 17, 2011 at 4:07 PM,bill.venab...@csiro.au wrote: Amen to all of that, Bert. Nicely put. The google style guide (not perfect, but a thoughtful contribution on these kinds of issues, has avoiding attach() as its very first line. See http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html) I would add, though, that not enough people seem yet to be aware of within(...), a companion of with(...) in a way, but used for modifying data frames or other kinds of list objects. It should be seen as a more flexible replacement for transform() (well, almost). The difference between with() and within() is as follows: with(data, expr, ...) allows you to evaluate 'expr' with 'data' providing the primary source for variables, and returns *the evaluated expression* as the result. By contrast within(data, expr, ...) again uses 'data' as the primary source for variables when evaluating 'expr', but now 'expr' is used to modify the varibles in 'data' and returns *the modified data set* as the result. I use this a lot in the data preparation phase of a project, especially, which is usually the longest, trickiest, most important, but least discussed aspect of any data analysis project. Here is a simple example using within() for something you cannot do in one step with transform(): polyData- within(data.frame(x = runif(500)), { x2- x^2 x3- x*x2 b- runif(4) eta- cbind(1,x,x2,x3) %*% b y- eta + rnorm(x, sd = 0.5) rm(b) }) check: str(polyData) 'data.frame': 500 obs. of 5 variables: $ x : num 0.5185 0.185 0.5566 0.2467 0.0178 ... $ y : num [1:500, 1] 1.343 0.888 0.583 0.187 0.855 ... $ eta: num [1:500, 1] 1.258 0.788 1.331 0.856 0.63 ... $ x3 : num 1.39e-01 6.33e-03 1.72e-01 1.50e-02 5.60e-06 ... $ x2 : num 0.268811 0.034224 0.309802 0.060844 0.000315 ... Bill Venables. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun
Re: [R] Problem with Princurve
You may have to tune the curve fitting parameters. Have a look at arguments 'smoother' and '...' in help(principal.curve), i.e. by default principal.curve() uses smoother function smooth.spline() in each iteration and principal.curve() passes down any additional arguments to it that you give (via '...'). So, look at help(smooth.spline) to see how you can adjust its tuning parameters. Hence, in order to troubleshoot, you may also want to play around with smooth.spline() on your data to see what is going on in the first iteration. /Henrik On Mon, May 23, 2011 at 6:58 AM, Ravi Varadhan rvarad...@jhmi.edu wrote: Why does this not find a better solution? x - seq(0,2*pi, length=1000) x - cbind(x/(2*pi), sin(x)) fit1 - principal.curve(x, plot = TRUE, trace = TRUE, maxit = 100, + start = cbind(sort(x[,1]), rep(1, nrow(x Starting curve---distance^2: 1499.5 Iteration 1---distance^2: 3.114789 Iteration 2---distance^2: 10.04492 Iteration 3---distance^2: 11.89215 Iteration 4---distance^2: 12.43235 Iteration 5---distance^2: 12.68524 Iteration 6---distance^2: 12.84443 Iteration 7---distance^2: 12.93624 Iteration 8---distance^2: 12.99118 Iteration 9---distance^2: 13.01280 Iteration 10---distance^2: 13.02867 Iteration 11---distance^2: 13.03867 You see that the projection distance is minimal at iteration 1, but the algorithm settles for an inferior projection (i..e. a greater projection distance). If I do not provide any starting values, I get this: fit1 - principal.curve(x, plot = TRUE, trace = TRUE, maxit = 100) Starting curve---distance^2: 29692.03 Iteration 1---distance^2: 20.31220 Iteration 2---distance^2: 19.45939 Iteration 3---distance^2: 19.26387 Iteration 4---distance^2: 19.20626 Iteration 5---distance^2: 19.18666 Iteration 6---distance^2: 19.18059 This is even worse. It seems like the algorithm is quite sensitive to starting values. Is this behavior expected or is there some flaw in the algorithm? Ravi. From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Gavin Simpson [gavin.simp...@ucl.ac.uk] Sent: Monday, May 23, 2011 8:27 AM To: guy33 Cc: r-help@r-project.org Subject: Re: [R] Problem with Princurve On Thu, 2011-05-19 at 06:43 -0700, guy33 wrote: Hey all, I can't seem to get the princurve package to produce correct results, even in the simplest cases. For example, if you just generate a 1 period noiseless sine wave, and ask for the principal curve and plot, the returned curve is clearly wrong (doesn't follow the sine wave). Here's my code: library(princurve) x - runif(1000,0,2*pi); x - cbind(x/(2*pi), sin(x)) fit1 - principal.curve(x, plot = TRUE) Anyone have any suggestions? If you run this code, do you get the correct principal curve? How about specifying some useful starting points? fit1 - principal.curve(x, plot = TRUE, trace = TRUE, maxit = 100, start = cbind(sort(x[,1]), rep(1, nrow(x And we need a few more iterations before convergence here. Starting from the first principal component for example might give useful starting points. HTH G Any help would be really appreciated! -guy33 -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-Princurve-tp3535721p3535721.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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rtools - The setup files are corrupted message when trying to install
FYI, Rtools212.exe: File size: 44,224,666 bytes MD5:15ce69dcfc989c43825bedeaa8389aa6 Rtools213.exe: File size: 38,122,354 bytes MD5: 09052655da7c6e8a81f2d398ed6004b5 /Henrik On Thu, Jun 9, 2011 at 6:12 AM, Martyn Byng martyn.b...@nag.co.uk wrote: Hi, Apologies if this is the wrong list to be sending this question to. I am trying to install a copy of the R tools required to create / compile packages on windows. After downloading Rtools from http://www.murdoch-sutherland.com/Rtools/ windows keeps complaining that The setup files are corrupted. This has happened with both the Rtools213.exe and the Rtools212.exe downloads, and on both 32 and 64 bit Windows 7. Does any one know what I might be doing incorrectly, or where else I should be downloading them from. Cheers Martyn The version of R that I want to eventually use these tools with is platform x86_64-pc-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 2 minor 13.0 year 2011 month 04 day 13 svn rev 55427 language R version.string R version 2.13.0 (2011-04-13) The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. Th...{{dropped:4}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merge large number of raster objects
See ?get and ?do.call. That should be enough. ?Reduce may be an alternative for do.call(), but could also be less memory efficient. My $.02 /Henrik On Thu, Jun 9, 2011 at 7:57 PM, Ben Zaitchik zaitc...@jhu.edu wrote: Hello, I have a large number of raster objects in memory, with names RH100, RH101, RH102, etc. (myobjects - ls(pattern='^RH')). These rasters are sections of a continuous map, and I would like to combine them using the RasterObject merge tool in package 'raster.' Merge expects an input list of raster objects (outmap-merge(x, y, ...), where x, y, and ... are raster objects). I can run the command successfully if I type in every raster object that I want to merge, but this is impractical for the large number of objects I'm combining. I would like to apply merge to a list of object names defined using some kind of wildcard-based list command, but I'm struggling to find the right data types in R. Is there some way to convert a vector of strings (e.g., as.vector(ls(pattern='^RH'))) to a vector of object names (as.names??) that could be specified as the input to the merge function? What I'd really like to do is something like outmap-merge(myobjects[1:40]), in order to merge the 40 raster objects, but I recognize that it might not be so simple. Advance apologies if this is already dealt with on the help list . . . I've gone in circles on wildcard, lapply, and names threads and haven't managed to get anything to work. Thank you, Ben __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merge large number of raster objects
...and ?mget for retrieving multiple objects as a list. /Henrik On Thu, Jun 9, 2011 at 10:32 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: See ?get and ?do.call. That should be enough. ?Reduce may be an alternative for do.call(), but could also be less memory efficient. My $.02 /Henrik On Thu, Jun 9, 2011 at 7:57 PM, Ben Zaitchik zaitc...@jhu.edu wrote: Hello, I have a large number of raster objects in memory, with names RH100, RH101, RH102, etc. (myobjects - ls(pattern='^RH')). These rasters are sections of a continuous map, and I would like to combine them using the RasterObject merge tool in package 'raster.' Merge expects an input list of raster objects (outmap-merge(x, y, ...), where x, y, and ... are raster objects). I can run the command successfully if I type in every raster object that I want to merge, but this is impractical for the large number of objects I'm combining. I would like to apply merge to a list of object names defined using some kind of wildcard-based list command, but I'm struggling to find the right data types in R. Is there some way to convert a vector of strings (e.g., as.vector(ls(pattern='^RH'))) to a vector of object names (as.names??) that could be specified as the input to the merge function? What I'd really like to do is something like outmap-merge(myobjects[1:40]), in order to merge the 40 raster objects, but I recognize that it might not be so simple. Advance apologies if this is already dealt with on the help list . . . I've gone in circles on wildcard, lapply, and names threads and haven't managed to get anything to work. Thank you, Ben __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question about R.oo package
Hi W. Kaisers, sorry for the delay - I just spotted you question: On Thu, Jun 16, 2011 at 5:52 AM, kais...@med.uni-duesseldorf.de wrote: Dear R.oo package users, while testing some functionality of the R.oo, I found that during the first construction of a object from a class, the constructor is twice called, but only one object is finalized. In all subsequent creation processes, the constructor is (expectedly) called once. Yes, this is the expected behavior. The reason is that the first time the constructor is called, a static instance of the class is also created (which is done by calling the constructor yet again without arguments). There is only one static instance of a class, so any following calls to the constructor will not spawn a second call. Related questions have been asked before and my answers then may clarify this further, e.g. [R] First call to constructor fails (R.oo), December 10, 2008 https://stat.ethz.ch/pipermail/r-help/2008-December/182212.html [R] Help with R.oo, July 17, 2009 https://stat.ethz.ch/pipermail/r-help/2009-July/204951.html Hope this helps Henrik Here some example code: library(R.oo) setConstructorS3(Test_class,function(val) { cat(constructor\n) if(missing(val)) val-NA; extend(Object(), Test_class, .val=val) }) setMethodS3(finalize,Test_class,function(this,...) { cat(destructor\n) }) o-Test_class(1) rm(o) gc() Is there any explanation for this behaviour? Thanks very much in advance W. Kaisers [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Querying the path separator?
See file.path(). /Henrik On Tue, Jun 28, 2011 at 6:59 PM, Jonathan Greenberg greenb...@ucdavis.edu wrote: Hopefully this is a pretty easy fix -- I need to have R query the path separator for some code I'm trying to write (it involves using a system() call) -- the call requires a path and a wildcard, e.g.: command=mycommand /path/to/*.files in the case of unix or, command=mycommand.exe C:\\path\\to\\*.files on a windows box System.which is working correctly, so the mycommand vs mycommand.exe part is working fine. The issue is that the /path/to should be set to getwd(), but this strips the trailing path separator. How do I go about querying the correct path separator for the system, so I can include it in a paste command (via sep=)? Thanks! --j -- Jonathan A. Greenberg, PhD Assistant Project Scientist Center for Spatial Technologies and Remote Sensing (CSTARS) Department of Land, Air and Water Resources University of California, Davis One Shields Avenue Davis, CA 95616 Phone: 415-763-5476 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read tab delimited file from a certain line
Christof, I've added support for this to the R.filesets package. In your case, then all you need to do is: library(R.filesets) dlf - readDataFrame(filename, skip=^year) No need to specify any other arguments - they're all automagically inferred - and the default is stringsAsFactors=FALSE. This is in R.filesets v2.0.0 which I still haven't published on CRAN. In the meanwhile, you can install it via: source(http://aroma-project.org/hbLite.R;) hbLite(R.filesets) /Henrik On Thu, Jan 17, 2013 at 1:34 AM, Christof Kluß ckl...@email.uni-kiel.de wrote: Hello thank you for the fast and helpful answer! Now the following works fine for me x - readLines(filename) i - grep(^year, x) dlf - read.table(textConnection(x[i:length(x)]), header = T, stringsAsFactors=F,sep=\t) Greetings Christof Am 16-01-2013 16:55, schrieb Rui Barradas: Hello, Read the file using readLines, then grep ^year. You can then use a textConnection to read.table: x - readLines(con = textConnection( informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 )) # This is it i - grep(^year, x) read.table(textConnection(x[i:length(x)]), header = TRUE) Hope this helps, Rui Barradas Em 16-01-2013 14:17, Christof Kluß escreveu: Hi I would like to read table data from a text-files with extra informations in the header (of unknown line count). Example: informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 ... If it was an excel file I could use something like read.xls(..., pattern=year) But it is a simple tab seperated text-file. Is there an easy way to read only the table? (Without dirty things ;)) Thx Christof __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hard Stop?
See abort() in the R.oo package, with some discussion here https://stat.ethz.ch/pipermail/r-devel/2012-September/064838.html /Henrik On Wed, Feb 6, 2013 at 7:05 PM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: stop() does not have momentum... it is designed to play nice. Perhaps you want ?options(error=). Alternately, you want to trigger a core dump? --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. ivo welch ivo.we...@anderson.ucla.edu wrote: is it possible to throw a stop() that is so hard that it will escape even tryCatch? /iaw Ivo Welch (ivo.we...@gmail.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Windows 7 installation issues
You probably meant testInstalledPackage(base) without the 's', cf. help(testInstalledPackage, package=tools). /Henri On Tue, May 29, 2012 at 4:18 PM, jalantho...@verizon.net jalantho...@verizon.net wrote: I installed R version 2.15.0 under C:/ on a PC running Windows 7. When I load library(tools) to test the installation and then run the command testInstalledPackages(base), I get the following error: Error in setwd(outDir): cannot change working directory. I have set up the R shortcut to run it as administrator. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Inconsistency using seq
FYI, isZero - function(x, neps=1, eps=.Machine$double.eps, ...) { + (abs(x) neps * eps) + } x - seq(from=0, to=4, by=0.1) isZero(x[4]-0.3) [1] TRUE isZero(x[4]-0.3, neps=1) [1] TRUE isZero(x[4]-0.3, neps=0.1) [1] FALSE You could also have called isZero() isValueSmallEnoughForWhatINeed(). My $.02 /Henrik On Mon, Jun 18, 2012 at 2:29 PM, Bert Gunter gunter.ber...@gene.com wrote: Nope. round() is not failsafe either. Basically, there is theoretically no way to guarantee immunity to floating point error in conditional comparisons. You need to either switch to integers -- which **are** exactly represented -- or figure out another way. Of course, practically speaking, sufficient rounding will work. It's just that it **can** always break. ... and you know Murphy's first law. -- Bert On Mon, Jun 18, 2012 at 1:54 PM, hamoreno hamor...@asu.edu wrote: Thanks everyone... Seems that I will have to use round before seq to make sure everything has the correct precision. -- View this message in context: http://r.789695.n4.nabble.com/Inconsistency-using-seq-tp4633739p4633750.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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Going backwards through plot panels
FYI, from help(layout, package=graphics): [...] Warnings These functions are totally incompatible with the other mechanisms for arranging plots on a device: par(mfrow), par(mfcol) and split.screen. /Henrik On Wed, Jun 20, 2012 at 3:17 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: That's fantastic Richard and much appreciated. It doesn't seem to play intuitively with layout() [and isn't documented to do so] but do you happen to know an alternative that works nicely with layout()? I'm trying to wrap my head around something like this: layout(matrix(c(1,1,2,3), byrow = TRUE, ncol = 2)) plot(1:5) par(mfg) # So the big panel seems to be c(1,1,2,2) plot(1:5) plot(1:5) # i and j seem not to make too much sense? par(mfg = c(2,1,2,2)) points(5:1, type = l, col = 2) # Why does this go back to bottom right? par(mfg = c(1,2,2,2)) points(5:1, type = l, col = 3) # Bottom left apparently? par(mfg = c(1,1)) points(5:1, type = l, col = 4) # Aspect ratio is funny or maybe its the margins? That last one is particularly strange to me. Anyways, it's much appreciated and I think it's worth giving up the variable sizing layout() affords to use this - thanks again, Michael On Wed, Jun 20, 2012 at 4:46 PM, Richard M. Heiberger r...@temple.edu wrote: ?par read about mfg which allows you to index into the arrangement set by mfrow and mfcol Rich On Wed, Jun 20, 2012 at 5:27 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: R-helpers, I'm looking to set up multi-screen plots with layout() or par(mfrow/mfcol = ) but I'm not sure if there's an easy way to go backwards among the panels. E.g. layout(1:2) plot(1:4) plot(1:8) Here I'd like to put some more on the 1:4 plot (e.g., some points or a line or a legend) but everything goes onto the now active panel. I'm really looking for something like dev.set() but for the panels on a single device. I know the immediate work around is simply to do all that's necessary for each panel in the right order, but I'm setting up some end-user-facing plot functions and that might not be the easiest to ask of them. For speed / style / consistency, I'd really like to stay with base graphics, so a grid solution unfortunately isn't quite what I need. Happy to be told to RTFM if someone has a pointer to the right one, Michael __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Having two different versions of a package in the same R installation
Install the two versions in two different *libraries* and update .libPaths() to prioritize one over the other. /Henrik On Tue, Oct 2, 2012 at 1:18 PM, Søren Højsgaard sor...@math.aau.dk wrote: Dear list, I am making some comparisons of two versions of the lme4 package: The CRAN version and the R-Forge version. For the moment I have two different R installations, each with a different version of lme4. However it would be convenient if I could have the same version within the same R installation such that I can run a code chunk on one lme4 version and immediately after run the same code chunk on another lme4 version. Does anyone know if this is possible? Best regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Download a file from url
You didn't say what errors you've got but you probably wants to specify argument mode=wb in your download.file() call, cf. https://stat.ethz.ch/pipermail/r-devel/2012-August/064739.html /Henrik On Mon, Oct 15, 2012 at 1:57 AM, veepsirtt veepsi...@gmail.com wrote: Hi Download the xls file from this link http://www.nseindia.com/content/fo/fii_stats_12-Oct-2012.xls http://www.nseindia.com/content/fo/fii_stats_12-Oct-2012.xls I tried this --- library(XLConnect) url = http://www.nseindia.com/content/fo/fii_stats_12-Oct-2012.xls; local.xls.file = tempfile() download.file(url, local.xls.file) wb = loadWorkbook(local.xls.file, create=F) data = readWorksheet(wb, sheet=1) View(data) --- no results ... kindly help me thanks veepsirtt -- View this message in context: http://r.789695.n4.nabble.com/Download-a-file-from-url-tp4642985p4646215.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Download a file from url
Have you tried downloading it manually using a web browser or similar? If so, compare that downloaded file to that you get from download.file() and see if they're the same. If the same, the problem is elsewhere (which is not unlikely to be the case). /H On Mon, Oct 15, 2012 at 6:15 PM, veepsirtt veepsi...@gmail.com wrote: Hi Henrik, i included the mode='wb' but gives me this error. What is the other method to download the excel file?. With kind regards veepsirtt library(XLConnect) url = http://www.nseindia.com/content/fo/fii_stats_12-Oct-2012.xls; local.xls.file = tempfile() download.file(url, local.xls.file, method='wget', mode='wb',extra=-U 'Mozilla/5.0 (X11; Linux) Gecko Firefox/5.0') Warning message: In download.file(url, local.xls.file, method = wget, mode = wb, : download had nonzero exit status wb = loadWorkbook(local.xls.file, create=F) Error: FileNotFoundException (Java): File 'filed0c141444d8' could not be found - you may specify to automatically create the file if not existing. data = readWorksheet(wb, sheet=1) Error in readWorksheet(wb, sheet = 1) : error in evaluating the argument 'object' in selecting a method for function 'readWorksheet': Error: object 'wb' not found On Mon, Oct 15, 2012 at 11:58 PM, Henrik Bengtsson-3 [via R] ml-node+s789695n4646268...@n4.nabble.com wrote: You didn't say what errors you've got but you probably wants to specify argument mode=wb in your download.file() call, cf. https://stat.ethz.ch/pipermail/r-devel/2012-August/064739.html /Henrik On Mon, Oct 15, 2012 at 1:57 AM, veepsirtt [hidden email]http://user/SendEmail.jtp?type=nodenode=4646268i=0 wrote: Hi Download the xls file from this link http://www.nseindia.com/content/fo/fii_stats_12-Oct-2012.xls http://www.nseindia.com/content/fo/fii_stats_12-Oct-2012.xls I tried this --- library(XLConnect) url = http://www.nseindia.com/content/fo/fii_stats_12-Oct-2012.xls; local.xls.file = tempfile() download.file(url, local.xls.file) wb = loadWorkbook(local.xls.file, create=F) data = readWorksheet(wb, sheet=1) View(data) --- no results ... kindly help me thanks veepsirtt -- View this message in context: http://r.789695.n4.nabble.com/Download-a-file-from-url-tp4642985p4646215.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4646268i=1mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4646268i=2mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Download-a-file-from-url-tp4642985p4646268.html To unsubscribe from Download a file from url, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4642985code=dmVlcHNpcnR0QGdtYWlsLmNvbXw0NjQyOTg1fDY5NzkzMTE3Nw== . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/Download-a-file-from-url-tp4642985p4646295.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] rJava not loading on Windows
Hi, I've successfully used it on a Linux setup, but when I try to load rJava on Windows 7 64-bit (session info below) I get: % R --vanilla library(rJava) Error : .onLoad failed in loadNamespace() for 'rJava', details: call: dirname(this$RuntimeLib) error: a character vector argument expected Error: package/namespace load failed for 'rJava' traceback() 2: stop(gettextf(package/namespace load failed for %s, sQuote(package)), call. = FALSE, domain = NA) 1: library(rJava) For the record, I have Java SDK installed and on the PATH: Sys.which(javac) javac C:\\PROGRA~1\\Java\\JDK17~1.0_0\\bin\\javac.exe system(javac -version) javac 1.7.0_02 Sys.which(java) java C:\\PROGRA~1\\Java\\JDK17~1.0_0\\bin\\java.exe system(java -version) java version 1.7.0_02 Java(TM) SE Runtime Environment (build 1.7.0_02-b13) Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode) I'm sure there is at least one other Windows user who bumped into this. Any suggestions how to fix/troubleshoot this? Thanks, Henrik sessionInfo() R version 2.15.2 Patched (2012-11-04 r61084) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.2 packageDescription(rJava) Package: rJava Version: 0.9-3 Title: Low-level R to Java interface Author: Simon Urbanek simon.urba...@r-project.org Maintainer: Simon Urbanek simon.urba...@r-project.org Depends: R (= 2.5.0), methods Description: Low-level interface to Java VM very much like .C/.Call and friends. Allows creation of objects, calling methods and accessing fields. License: GPL-2 URL: http://www.rforge.net/rJava/ SystemRequirements: java Repository: CRAN Date/Publication: 2011-12-11 10:41:33 Built: R 2.15.2; i386-w64-mingw32; 2012-10-31 19:21:34 UTC; windows sessionInfo() R Under development (unstable) (2012-11-04 r61084) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.16.0 packageDescription(rJava) Package: rJava Version: 0.9-3.1 Title: Low-level R to Java interface Author: Simon Urbanek simon.urba...@r-project.org Maintainer: Simon Urbanek simon.urba...@r-project.org Depends: R (= 2.5.0), methods Description: Low-level interface to Java VM very much like .C/.Call and friends. Allows creation of objects, calling methods and accessing fields. License: GPL-2 URL: http://www.rforge.net/rJava/ SystemRequirements: java Repository: CRAN Date/Publication: 2011-12-11 10:41:33 Packaged: 2012-10-19 17:13:34 UTC; biocbuild Built: R 2.16.0; i386-w64-mingw32; 2012-10-19 17:36:53 UTC; windows __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Setting default graphics device options
Hi, see the R.devices package [http://cran.r-project.org/web/packages/R.devices/]. FYI, there is a vignette [R.devices-overview.pdf], but for some reason it's hard find. However it is there: help.start() - R.devices - 'User guides, package vignettes and other documentation.' - R.devices-overview.pdf. First, don't forget to call library(R.devices). CREATE IMAGE FILE ATOMICALLY: To create a PNG image file 'GaussianDensity.png' in subdirectory figures/ (of the current working directory), do: toPNG(GaussianDensity, aspectRatio=0.6, scale=2, { curve(dnorm, from=-5, to=+5) }) This will, while still using png()/dev.off() internally, (1) automatically add filename extension, (2) set the height of the image as 0.6 times the default width, (3) rescale height and width to be 2 times the default, and (3) make sure the PNG device is closed afterward (no more forgetting about dev.off()). It's also make sure not to leave incomplete image files behind in case there's an error in your plot code. There's an option to change that behavior too, e.g. so it instead renames the incomplete file for easy identification. DEFAULT OUTPUT DIRECTORY: You can set the default output directory as: options(devEval/args/path=/srv/samba/share/) Then, whenever you call toPNG(), it will instead save the file to /srv/samba/share/. If the directory is missing, it will be created automatically. DEFAULT FILENAME: Currently it is not possible to set a default filename pattern. However, you can do something like: imgname - function() { # NOTE: No filename extension sprintf(Rplot-%s, format(Sys.time(), %Y%m%d-%H%M%S)) } and then use: toPNG(imgname(), aspectRatio=0.6, scale=2, { curve(dnorm, from=-5, to=+5) }) (I'll think about adding support for a default image name format). DEFAULT DEVICE OPTIONS: To change the default image dimensions, do: devOptions(png, width=1280, height=800); Importantly, in order for these devOptions() to apply, you must use toPNG() [or devEval(png)]; they won't apply if you call png() explicitly. To check the default options, do: str(devOptions(png)) List of 11 $ filename : chr Rplot%03d.png $ units : chr px $ pointsize : num 12 $ bg: chr white $ res : logi NA $ family: chr sans $ restoreConsole: logi TRUE $ type : language c(windows, cairo, cairo-png) $ antialias : language c(default, none, cleartype, grey, subpixel ) $ width : num 1280 $ height: num 800 The default defaults are inferred from the default in R, so if you don't change anything you'll get the same output as calling png()/dev.off(). BTW, unless all of your images should have aspect ratio 800/1280=0.625, I'd recommend to use square defaults (just as the png() device do), e.g. devOptions(png, width=1280, height=1280), and then specify aspectRatio=0.625 in your toPNG() calls. In addition to toPNG(), there are also toBMP(), toEPS(), toPDF(), toSVG() and toTIFF(), with their own devOptions() settings. Hope this is useful Henrik PS. From your example where all images have the same filename format with timestamps, it almost looks like you want to do an automatic log/archiving of image files generated. If so, I also have the R.archive package (not yet on CRAN) in development. All you need to do is load that package and everything else will be automatic. Whenever R.devices creates an image file (e.g. via toPNG()), a copy of it will be saved to ~/.Rarchive/%Y%m%d/%H%M%OS3-imgname.ext, e.g. ~/.Rarchive/2013-05-26/100330.684_GaussianDensity.png. For every toPNG(), toPDF() etc another copy will be created with a unique filename. That is useful when you do lots to EDA and want to go back to that image you did a couple of hours ago. If this is what you want, let me know and I'll show you how to get access to R.archive. On Sun, May 26, 2013 at 8:20 AM, Vishal Belsare shoot.s...@gmail.com wrote: Hi, Is it possible to : [1] set a default location to plot graphs in png format with specific dimensions resolution. I want to plot to a directory which is a shared on the network (samba share), so as to view the plots from a different machine. prior2plot - function() {plotfile - paste('/srv/samba/share/Rplot-', as.character(format(Sys.time(), %Y%m%d-%H%M%S)), '.png', sep=''); png(filename=plotfile, width=1280, height=800)} [2] call dev.off() 'automagically' after a call to the plot function, by (somehow) setting it as a default behavior in .Rprofile.site? This would be nice to have, so as to update an image viewer running on a local machine which keeps displaying the image(s) in the shared plot folder on the remote machine (which runs R) I was thinking on the lines of adding the following to .Rprofile.site : __ prior2plot - function() {plotfile - paste('/srv/samba/share/Rplot-', as.character(format(Sys.time(), %Y%m%d-%H%M%S)), '.png', sep=''); png(filename=plotfile, width=1280, height=800)}
Re: [R] Setting default graphics device options
Sorry, forgot to add: Hi, [a somewhat different approach but] see the R.devices package /Henrik On Sun, May 26, 2013 at 10:14 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, see the R.devices package [http://cran.r-project.org/web/packages/R.devices/]. FYI, there is a vignette [R.devices-overview.pdf], but for some reason it's hard find. However it is there: help.start() - R.devices - 'User guides, package vignettes and other documentation.' - R.devices-overview.pdf. First, don't forget to call library(R.devices). CREATE IMAGE FILE ATOMICALLY: To create a PNG image file 'GaussianDensity.png' in subdirectory figures/ (of the current working directory), do: toPNG(GaussianDensity, aspectRatio=0.6, scale=2, { curve(dnorm, from=-5, to=+5) }) This will, while still using png()/dev.off() internally, (1) automatically add filename extension, (2) set the height of the image as 0.6 times the default width, (3) rescale height and width to be 2 times the default, and (3) make sure the PNG device is closed afterward (no more forgetting about dev.off()). It's also make sure not to leave incomplete image files behind in case there's an error in your plot code. There's an option to change that behavior too, e.g. so it instead renames the incomplete file for easy identification. DEFAULT OUTPUT DIRECTORY: You can set the default output directory as: options(devEval/args/path=/srv/samba/share/) Then, whenever you call toPNG(), it will instead save the file to /srv/samba/share/. If the directory is missing, it will be created automatically. DEFAULT FILENAME: Currently it is not possible to set a default filename pattern. However, you can do something like: imgname - function() { # NOTE: No filename extension sprintf(Rplot-%s, format(Sys.time(), %Y%m%d-%H%M%S)) } and then use: toPNG(imgname(), aspectRatio=0.6, scale=2, { curve(dnorm, from=-5, to=+5) }) (I'll think about adding support for a default image name format). DEFAULT DEVICE OPTIONS: To change the default image dimensions, do: devOptions(png, width=1280, height=800); Importantly, in order for these devOptions() to apply, you must use toPNG() [or devEval(png)]; they won't apply if you call png() explicitly. To check the default options, do: str(devOptions(png)) List of 11 $ filename : chr Rplot%03d.png $ units : chr px $ pointsize : num 12 $ bg: chr white $ res : logi NA $ family: chr sans $ restoreConsole: logi TRUE $ type : language c(windows, cairo, cairo-png) $ antialias : language c(default, none, cleartype, grey, subpixel ) $ width : num 1280 $ height: num 800 The default defaults are inferred from the default in R, so if you don't change anything you'll get the same output as calling png()/dev.off(). BTW, unless all of your images should have aspect ratio 800/1280=0.625, I'd recommend to use square defaults (just as the png() device do), e.g. devOptions(png, width=1280, height=1280), and then specify aspectRatio=0.625 in your toPNG() calls. In addition to toPNG(), there are also toBMP(), toEPS(), toPDF(), toSVG() and toTIFF(), with their own devOptions() settings. Hope this is useful Henrik PS. From your example where all images have the same filename format with timestamps, it almost looks like you want to do an automatic log/archiving of image files generated. If so, I also have the R.archive package (not yet on CRAN) in development. All you need to do is load that package and everything else will be automatic. Whenever R.devices creates an image file (e.g. via toPNG()), a copy of it will be saved to ~/.Rarchive/%Y%m%d/%H%M%OS3-imgname.ext, e.g. ~/.Rarchive/2013-05-26/100330.684_GaussianDensity.png. For every toPNG(), toPDF() etc another copy will be created with a unique filename. That is useful when you do lots to EDA and want to go back to that image you did a couple of hours ago. If this is what you want, let me know and I'll show you how to get access to R.archive. On Sun, May 26, 2013 at 8:20 AM, Vishal Belsare shoot.s...@gmail.com wrote: Hi, Is it possible to : [1] set a default location to plot graphs in png format with specific dimensions resolution. I want to plot to a directory which is a shared on the network (samba share), so as to view the plots from a different machine. prior2plot - function() {plotfile - paste('/srv/samba/share/Rplot-', as.character(format(Sys.time(), %Y%m%d-%H%M%S)), '.png', sep=''); png(filename=plotfile, width=1280, height=800)} [2] call dev.off() 'automagically' after a call to the plot function, by (somehow) setting it as a default behavior in .Rprofile.site? This would be nice to have, so as to update an image viewer running on a local machine which keeps displaying the image(s) in the shared plot folder on the remote machine (which runs R) I was thinking on the lines
Re: [R] Bytes to Numeric/Float conversion
On Tue, Jun 11, 2013 at 2:14 PM, David Winsemius dwinsem...@comcast.net wrote: On Jun 11, 2013, at 9:01 AM, Bikash Agrawal wrote: Is there any packages available in R, that can convert Bytes array to Float. Using rJava we can do it. But it is kind of slow. Is there any R specific packages. I am having problem converting my bytes array to floating point. Could any one help me with this problem. There is a raw data type that is designed to hold bytes than can be indexed. ?raw ...and then ?readBin /Henrik `scan` can read files of type raw ?scan -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stopping functions with long execution times
See evalWithTimeout() of R.utils, e.g. tryCatch({ evalWithTimeout({ slowFunction(); }, timeout=7*24*3600); }, TimeoutException=function(ex) { cat(Timeout. Skipping.\n); }) help(evalWithTimeout) have more information and cross links. /Henrik On Thu, Jul 18, 2013 at 11:37 AM, ONKELINX, Thierry thierry.onkel...@inbo.be wrote: Dear all, I am running the same model on several datasets, each dataset is a different species. The problem is that for some datasets the model is not converging. Currently I have an INLA model running for 35 days and still no results. The process still uses near 100% of the CPU and less than 1 GB RAM on virtual Ubuntu box with 8 GB RAM on a blade server. I can kill the process manual and make the script skip this model. However it would be more elegant if it was possible to automate this. E.g. let the model run but kill it automatically once it runs for more than 7 days. Once killed the model should throw an error so we can catch that in the error-handling. Any suggestions on how to do this? Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Chinese characters in html source captured by download.file() are garbled code , how to convert it readable
Try with adding mode=wb to download.file(), or just use downloadFile() of R.utils. /Henrik On Sun, Jul 28, 2013 at 8:32 PM, Yong Wang wangyo...@gmail.com wrote: Dear list, I am working with R to download numerous html source code from which the data extracted will be further processed. The problem is the Chinese character in the html source code are all garbled and I can't really find a way to convert them to something readable. This problem persists on ubuntu-10 and win-7, English environment. Not try Operating system in Chinese yet. I know literally nothing about encoding and a comprehensive search online does not save me from this woe. # the code download.file( https://www.google.com.hk/finance/company_news?q=SHA:601857gl=cnnum=200 ,destfile=tmp.txt) test-readLines(tmp.txt,encoding=UTF-8) #the garbled code in tmp.txt and test is like below #��#22269;�۪o�ѵM�a�ѥq�]� Any help is highly appreciated. yong [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] package environment versus namespace environment
See Suraj Gupta's online article 'How R Searches and Finds Stuff' from March 29, 2012: http://obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/ It's a very useful write up on this topic. /Henrik On Sat, Mar 8, 2014 at 3:42 PM, Benjamin Tyner bty...@gmail.com wrote: Duncan, Thank you for the informative link. So, do the loaded namespaces have an ordering akin to the package search path that determines that functions in the base namespace can see objects in the utils namespace? (I noticed that loadedNamespaces() just comes back in alphabetical order.) Regards Ben On 03/07/2014 11:46 AM, Duncan Murdoch wrote: On 07/03/2014 10:16 AM, Benjamin Tyner wrote: Hello, I realize that a function in environment: base (for example, function head1 below) is unable to see (without resorting to ::, anyway) objects in utils (for example, head below), since package:base is after package:utils on the search path. However, I'm wondering what is the machinery that allows a function in environment: namespace:base (for example, function head2 below) to be able to see head just fine, without needing to resort to ::. See Luke Tierney's article in R News, Name space management for R. Luke Tierney, R News, 3(1):2-6, June 2003 [1]http://cran.r-project.org/doc/Rnews/Rnews_2003-1.pdf There's a link to it from the R help system. Run help.start(), then look at Technical papers in the Miscellaneous Material section. I believe most of what it says is still current; the only thing I can see at a glance that is no longer correct is that in those days namespaces were optional in packages. Now all packages have namespaces. Duncan Murdoch I'm also wondering more generally, why there is a need (practically speaking) for a distinction between the environment associated with a package and the environment associated with the namespace. $ export R_PROFILE=/home/btyner/Rprofile.site $ cat /home/btyner/Rprofile.site sys.source(/home/btyner/head1.R, envir = baseenv()) sys.source(/home/btyner/head2.R, envir = .BaseNamespaceEnv) $ cat /home/btyner/head1.R head1 - function(x) head(x) $ cat /home/btyner/head2.R head2 - function(x) head(x) $ Rscript -e head1(letters) Error in head1(letters) : could not find function head Execution halted $ Rscript -e head2(letters) [1] a b c d e f $ Rscript -e sessionInfo() R version 3.0.1 (2013-05-16) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets base Regards Ben __ [2]R-help@r-project.org mailing list [3]https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide [4]http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- References 1. http://cran.r-project.org/doc/Rnews/Rnews_2003-1.pdf 2. mailto:R-help@r-project.org 3. https://stat.ethz.ch/mailman/listinfo/r-help 4. http://www.R-project.org/posting-guide.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] pre-allocation not always a timesaver
I don't think you got a response to this one; x - array(dim=(c(j, n))) for (i in 1:n) { x[,i] - rnorm(j) } Note that array() allocates a logical array by default, which means that in your first iteration (i==1) it has to be coerced to a double array before assigning the value of rnorm(). That takes time. It also takes time to garbage collect the stray logical array afterward. Using, x - array(NA_real_, dim=(c(j, n))) for (i in 1:n) { x[,i] - rnorm(j) } avoids this. For updating list elements, you can avoid repetitive overhead from $- and $ by replacing: a$myx - array(dim=c(j, n)) for (i in 1:n) { a$myx[,i] - rnorm(j) } a$myx with myx - array(NA_real, dim=c(j, n)) for (i in 1:n) { myx[,i] - rnorm(j) } a$myx - myx myx Similarly for S4 slots and @- and @. /Henrik On Thu, Feb 27, 2014 at 7:53 PM, Ross Boylan r...@biostat.ucsf.edu wrote: The R Inferno advises that if you are building up results in pieces it's best to pre-allocate the result object and fill it in. In some testing, I see a benefit with this strategy for regular variables. However, when the results are held by a class, the opposite seems to be the case. Comments? Explanations? Possibly for classes any update causes the entire object to be replaced--perhaps to trigger the validation machinery?--and so preallocation simply means on average a bigger object is being manipulated. Here is some test code, with CPU seconds given in the comments. I tried everything twice in case there was some first-time overhead such as growing total memory in the image. When the 2 times differed noticeably I reported both values. # class definitions refbase - setRefClass(refBase, fields = list(dispatch=ANY, myx=ANY), methods = list( initialize = function(x0=NULL, ...) { usingMethods(foo) dispatch - foo myx - x0 } # some irrelevant methods edited out )) myclass - setClass(simple, representation=list(myx=ANY)) ### Method 1: regular variables pre - function(n, j=1000) { x - array(dim=(c(j, n))) for (i in 1:n) { x[,i] - rnorm(j) } x } system.time(pre(1000)) #0.3s nopre - function(n, j=1000) { x - numeric(0) for (i in 1:n) x - c(x, rnorm(j)) x } system.time(nopre(1000)) # 2.0s, 2.7s # Method 2: with ref class pre2 - function(n, j=1000) { a - refbase(x0=numeric(0)) a$myx - array(dim=c(j, n)) for (i in 1:n) { a$myx[,i] - rnorm(j) } a$myx } system.time(pre2(1000)) # 4.0 s nopre2 - function(n, j=1000) { a - refbase(x0=numeric(0)) for (i in 1:n) a$myx - c(a$myx, rnorm(j)) a$myx } system.time(nopre2(1000)) # 2.9s, 4.3 # Method 3: with regular class pre3 - function(n, j=1000) { a - myclass() a@myx - array(dim=c(j, n)) for (i in 1:n) { a@myx[,i] - rnorm(j) } a@myx } system.time(pre3(1000)) # 7.3 s nopre3 - function(n, j=1000) { a - myclass(myx=numeric(0)) for (i in 1:n) a@myx - c(a@myx, rnorm(j)) a@myx } system.time(nopre3(1000)) # 4.2s __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to implement a recurring check for updates for R and packages?
[Sounds like a question for R-devel] On Wed, Apr 9, 2014 at 5:02 AM, Tal Galili tal.gal...@gmail.com wrote: Hello all, I wish to add to the installrhttp://cran.r-project.org/web/packages/installr/package the ability to check for new versions of R once every X units of time (maybe once every two weeks). I would like to keep a time stamp somewhere, that would stay persistent across R sessions (i.e.: that if I turn R off and then back on, it would keep track of the last time it checked for a new R version). It would be best if I could save some file, maybe in the installr package folder, that would keep track of that. Any suggestions or best practice on how to implement something like that? I'm not aware of any standards for where to store site- and/or user-specific R settings that are persistent across session. It would certainly nice to have a standard, instead of everyone inventing their own. Either way, before starting it is useful (even if you don't distribute via CRAN) if you're aware of the following passage from http://cran.r-project.org/web/packages/policies.html provides a fair guideline: - Packages should not write in the users’ home filespace, nor anywhere else on the file system apart from the R session’s temporary directory (or during installation in the location pointed to by TMPDIR: and such usage should be cleaned up). Installing into the system’s R installation (e.g., scripts to its bin directory) is not allowed. Limited exceptions may be allowed in interactive sessions if the package obtains confirmation from the user. Then have a look the R.cache package. It is used for caching objects to file, e.g. memoization of computational expensive results. It addresses the above policy in the following way: 1. It checks whether ~/.Rcache/ exists or not. If it exists, it is assumed that it already has the user's permission. 2 Otherwise, if in an interactive R session, it asks the user for permission to create that directory. If successful it is created (and it drops an informative README.txt file in there too), otherwise it uses a temporary directory. Here is what it looks like to first time you load R.cache: library(R.cache) The R.cache package needs to create a directory that will hold cache files. It is convenient to use one in the user's home directory, because it remains also after restarting R. Do you wish to create the '~/.Rcache/' directory? If not, a temporary directory (C:\Users\hb\AppData\Local\Temp\Rtmp61upx7/.Rcache) that is specific to this R session will be used. [Y/n]: You can use a similar strategy. You could also use R.cache for you own purposes, e.g. readURL - function(url, maxAge=10*24*3600, force=FALSE, ...) { library(R.cache) dirs - installr # = Caching to ~/.Rcache/installr/ key - list(method=readURL, url=url) # Check for cached results bfr - loadCache(key=key, dirs=dirs) when - attr(bfr, when) # Recent enough results already available? if (!force !is.null(when) (Sys.time()-maxAge = when)) return(bfr); # Download and memoize bfr - readLines(url) attr(bfr, when) - Sys.time() saveCache(bfr, key=key, dirs=dirs) bfr } # readURL() That would memoize the results from CRAN (for 10 days by default); you can of course cache the parsed R version etc, but I leave that to you. /Henrik (author of R.cache) Thanks, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stop a function
Two quick comments: 1. You do not need to reset the timeout limits yourself; it's already taken care of, cf. help(evalWithTimeout). 2. Have you tried example(evalWithTimeout)? It should illustrate how it works/is used. It's also a good example to verify that it also works on your machine (I'd be really surprised if it doesn't). When you have confirmed that example code works, then extend it. Hope this helps. Unfortunately, that's all we can help you with (unless you send a minimal reproducible example that we can also test on our end). /Henrik On Wed, May 14, 2014 at 1:05 AM, n omranian n_omran...@yahoo.com wrote: Here is my code... I tried to remove many parts and keep the part which is related to evalWithTimeout. I have two similar while(1) loop in my original code. I only include one here. tnx a lot NO while (perm = 1000) { setTimeLimit(cpu = Inf, elapsed = Inf) while (1) { data - main_data[,sample(1:ncol(main_data),size=10,replace=F)] dd - while(i= dd) { y - time[i,] fit - NULL tryCatch(fit - {evalWithTimeout({penalized(y,x,lambda1=lambda1[i],lambda2=lambda2[i],fusedl=a,standardize=T,trace=F);}, timeout=360)}, TimeoutException = function(ex) cat(Timeout. Skipping.\n)) setTimeLimit(cpu = Inf, elapsed = Inf) if (is.null(fit)==T) break i-i+1 } if (idd) break } perm-perm+1 } On Wednesday, May 14, 2014 9:50 AM, ONKELINX, Thierry thierry.onkel...@inbo.be wrote: Yes. Give us a minimal and reproducible example of your code and don't post in HTML. See fortunes::fortune(244) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey Van: n omranian [mailto:n_omran...@yahoo.com] Verzonden: dinsdag 13 mei 2014 22:13 Aan: ONKELINX, Thierry; r-packages-ow...@r-project.org; r-help@r-project.org; r-help-requ...@r-project.org Onderwerp: Re: [R] stop a function Hi, Another problem arised now. I got this error: Error in match(x, table, nomatch = 0L) : reached CPU time limit I googled it but nothing could help me to get rid of this error. Any comments, help or hints? Thanks a lot, NO On Tuesday, May 13, 2014 2:36 PM, ONKELINX, Thierry thierry.onkel...@inbo.be wrote: Have a look at evalWithTimeout() from the R.utils package Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens n omranian Verzonden: dinsdag 13 mei 2014 14:15 Aan: r-packages-ow...@r-project.org; r-help@r-project.org; r-help-requ...@r-project.org Onderwerp: [R] stop a function Hi all, If I use a function in R which takes some parameters as an input, how can I stop this function in the while loop and try another parameter in case the function takes long time or could not converge. Actually, I'm using penalized function in a loop for some fixed lambdas (pre-calculated), for some of them the function converged, but for some not. Now I decide to proceed in this way that if it takes longer than 3 mins, stop the penalized function and try the other lambdas. I need to do it in the loop since the loop is in the big program and I can't manually stop and begin again. Looking forward to your reply. NO [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide
Re: [R] R-memory: clearing memory within a function?
See blog post 'Speed trick: Assigning large object NULL is much faster than using rm()!': http://www.jottr.org/2013/05/speed-trick-assigning-large-object-null.html /Henrik On Tue, Jun 3, 2014 at 5:35 PM, Ista Zahn istaz...@gmail.com wrote: Hi Frank, I don't think it is possible to state a general rule about which will be faster. For example this system.time({ for(i in 1:1) { x - matrix(rnorm(10), ncol = 10) y - mean(x) #rm(x) z - matrix(runif(10), ncol = 100) #rm(z) } }) gets a lot slower if I uncomment the rm() lines, but this system.time({ for(i in 1:5) { x - matrix(rnorm(1000), ncol = 10) y - mean(x) rm(x) z - matrix(runif(1000), ncol = 100) rm(z) } }) is slightly faster than it would be without the rm() lines. I think you'll have to run a smaller version of the simulation both ways and see which is faster. Best, Ista On Tue, Jun 3, 2014 at 10:05 AM, Frank van Berkum frankieboy...@hotmail.com wrote: Dear R-users, I'm working on a project in which many simulations have to be performed within functions. The simulations are quite time consuming. I thought that in general an empty memory is better for speed performance than a full memory. If I call a function which performs simulations within the function, than the memory will temporarily increase (while the function is executed and objects are created within the function), but as soon as the function is finished, temporarily objects are flushed. It seems as if it might be beneficial for speed performance to clear objects from the memory within the function if they are no longer needed in the remainder of the function. Does anyone know whether this is actually the case? Thanks in advance! Frank [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] as.character.call?
cl - quote(round(10.5)) deparse(cl) [1] round(10.5) /Henrik On Tue, Jun 3, 2014 at 8:07 PM, Spencer Graves spencer.gra...@structuremonitoring.com wrote: How can I get a call object as a character string? Example: cl - quote(round(10.5)) str(cl) language round(10.5) as.character(cl) [1] round 10.5 How can I get round(10.5)? I can get this answer for this toy problem with paste0(paste(as.character(cl), collapse='('), ')'). However, that's not a general solution. Thanks, Spencer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] .Rprofile: contains invalid line(s)
Make sure that the last line has a newline at the end, otherwise that expression will be silently ignored, cf. R-devel thread '[Rd] Last line in .Rprofile must have newline (PR#4056)' on 2003-09-03 [https://stat.ethz.ch/pipermail/r-devel/2003-September/027455.html]. I'm pretty sure many many people have been bitten by this feature. Other than that, add a message(.Rprofile...) and the very top and a message(.Rprofile...done) at the very bottom to confirm that ~/.Rprofile is loaded/evaluated. /Henrik On Thu, Jun 5, 2014 at 10:58 AM, Ista Zahn istaz...@gmail.com wrote: Hi Stephan, R_ENVIRON should not point to your .Rpofile, use R_PROFILE_USER for that. See ?Startup for details. Best, Ista On Thu, Jun 5, 2014 at 10:18 AM, Stephen Davies step...@umw.edu wrote: At some point in the recent past, my local .Rprofile has ceased to be executed on startup. I've upgraded R several times in the last few months, and am unsure which version caused this problem. Currently I'm running version 3.1.0 (2014-04-10) Spring Dance on 64-bit Ubuntu. My symptoms and fix attempts: 1) Changes I make to .Rprofile are no longer automatically recognized by R on startup. 2) After some Googling, I was led to believe that I need to set the environment variable R_ENVIRON to /home/stephen/.Rprofile. But after doing so, when I start R, I get an error message: File /home/stephen/.Rprofile contains invalid line(s). Then it lists the contents of .Rprofile, which are now simply: .First - function() { joe - function(x) x*2 } This file is perfectly valid, however, which I know because when I explicitly source() it, it loads .First just fine, and if I run .First(), I can then successfully run joe(3). Why does R say this .Rprofile is invalid on startup? Is setting R_ENVIRON, as described, the correct procedure? And why did this suddenly become necessary? - Stephen Davies, Ph.D. (step...@umw.edu) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] return the name of source.
See findSourceTraceback() of R.utils. /Henrik On Mon, Aug 26, 2013 at 10:58 PM, peter dalgaard pda...@gmail.com wrote: On Aug 27, 2013, at 07:12 , nevil amos wrote: Is there a fuction that will allow me to retrun the filename for a script from within that script. Not a standard one, but you should be able to get at it via a bit of breaking and entering: sys.status() and friends (sys.calls, sys.frames) give you access to the evaluation frame of source() which contains a variable called file. -pd fir instance If I have a script myscript.r: FileName-unknown.fucntion() print(FileName) and run it source(myscript.r) will return myscript.r Thanks Nevil Amos [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Installing package from website
On Sun, Aug 25, 2013 at 10:55 AM, Christofer Bogaso bogaso.christo...@gmail.com wrote: Hello again, I need to install Rmpi package from this http://www.stats.uwo.ca/faculty/yu/Rmpi/download/windows/MPICH2 I was wondering if there is any direct way to install this in R. The trivial method would obviously be download and save the required zip file in the local disk and install it from there. R.utils::installPackages(url) /Henrik Any idea? Thanks and regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help: concurrent R sessions for different settings of simulations
I strongly suggest to use the BatchJobs package [http://cran.r-project.org/web/packages/BatchJobs] for this. It is easy to install and cross platform and does not rely on external software such as perl. It allows you develop your script running sequentially/interactively on your local machine/laptop, the via *a single configuration file* (./.BatchJobs.R) you can use the exact same script to distribute the jobs to separate R sessions either on multiple cores on the same machine or on a cluster (most common cluster types are supported). The learning curve is not that step - as with most parallel computations you have to move away from using for loops to using lapply() and then you're almost done. /Henrik On Sun, Sep 29, 2013 at 10:22 AM, Chee Chen chee.c...@yahoo.com wrote: Dear All, I have spent almost 2 days but did not succeed yet. Problem description: I have 3 parameters, p1, p2 and p3, for which p1 take 1 of 5 possible distributions (e.g., normal, laplace), p2 takes 1 of 3 possible distributions, and p3 takes 1 of 5 possible distribution. These 3 parameters create 75 settings, and these 3 parameters are arguments of a function F; and F is part of simulation codes. To summarize: different value of the ordered triple (p1,p2,p3) means different setting and this is the only difference in the simulation codes. Target to achieve: instead of loop through each of the 75 settings one after another, I would like to concurrently run all 75 settings on the cluster. My attempts: via loops, I used Perl to create 75 files, each for a different triple (p1,p2,p3), and Perl uses system(R ..) to execute this setting once it is created. The Perl codes are submitted to cluster correctly. But when I looked into the log file, the cluster still executes it one setting after another setting. Request: any help is appreciated! It is because of the loops of Perl that executes a setting once it is created? Have a nice day! Chee [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] When to use RProfile.site or .Rprofile
Unless you're trying to provide your startup settings to multiple users (typically only sysadms do this), stick with .Rprofile (in your home directory). There is no need to have one per working directory, unless they differ, cf. ?Startup [...a file called ‘.Rprofile’ is searched for in the current directory or in the user's home directory (in that order).]. Also, RProfile.site resides where R is installed (e.g. R_HOME/etc/). Maintaining that one requires updates when the R version/installation location is updated, whereas the one in you home directory will always be found regardless of R version. My $.02 /Henrik On Thu, Oct 3, 2013 at 9:10 AM, jroyrobert...@comcast.net wrote: I would appreciate some advice on what the preferred contents of RProfile.site vs. .Rprofile should be. A .First() function can reside in either one, but is it preferred to place it in .Rprofile? I currently use .First() in .Rprofile files placed in separate directories used for different RStudio projects. Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] system2 commands with backslash
system2(sed, args=c(-i, s/oldword\\s/newword/g, d:/junk/x/test.tex)) /Henrik On Fri, Oct 11, 2013 at 8:58 AM, David Winsemius dwinsem...@comcast.net wrote: On Oct 10, 2013, at 8:16 AM, Zev Ross wrote: Hi All, I'm trying to edit a file in place using system2 and sed from within R. I can get my command to work unless there is a backslash in the command in which case I'm warned about an unrecognized escape. So, for example: system2(sed -i s/oldword/newword/g d:/junk/x/test.tex) # works fine system2(sed -i s/oldword\s/newword/g d:/junk/x/test.tex) # does not work in R (the command works on the command line) I've experimented with double slashes to escape the \s, Wouldn't you want to double the backslashes instead? I've tried the shell command, I've tried experimenting with shQuote and can't seem to get around the unrecognized escape issue. By the way, it would be preferable to have a solution that avoided using double backslashes etc because, unfortunately, in my real-world example, I'm actually replacing double slashes and would prefer not to have quadruple slashes etc. I'm using Windows 7, 64 bit. Zev -- Zev Ross ZevRoss Spatial Analysis 120 N Aurora, Suite 3A Ithaca, NY 14850 607-277-0004 (phone) z...@zevross.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. David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R - How to physically Increase Speed
On Mon, Oct 21, 2013 at 4:12 PM, Alexandre Khelifa akhel...@logitech.com wrote: Hi, My name is Alexandre Khelifa and I have been using R at my work for about 2 years. I have been working on a project when we do Monte Carlo Simulation and it involves a lot of calculations. I am currently using R x64.3.0.1 and used to work on a 4GB machine. However, the calculation time was very long (about 2 weeks), and the IT team and I decided to add more memory and to make it a 8GB virtual machine. I also added the following line in my code: * * - *options(java.parameters = -Xmx8192m) * I re-did the same calculations (4GB vs. 8GB) but did not see a significant increase in the calculation time, so I was wondering if I did anything wrong and/or what would be the best solution to increase this time. If you and your team travel Earth-to-Space round trip at 87% the speed of light, your computations would *physically* become roughly twice as fast (you must leave computer behind). Alternatively, look at help(package=parallel). But what really makes a difference is to find and replace bottle necks in your code by profiling it, cf. help(Rprof). I'd go with the latter if you haven't already done so. /Henrik Thanks a lot for your help and more generally for building such an amazing (and free) tool. Let me know if you have any questions. Regards, Alexandre Khelifa [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Depends and Imports in DESCRIPTION file
On Tue, Oct 22, 2013 at 8:03 PM, Marc Girondot marc_...@yahoo.fr wrote: Dear list members: I try to check my updated package to include a new version in CRAN (phenology) but a new error is indicated and I don't find the logic. First my system: * using R version 3.0.2 Patched (2013-09-27 r64011) * using platform: x86_64-apple-darwin10.8.0 (64-bit) Here is the message: * checking dependencies in R code ... NOTE Packages in Depends field not imported from: ‘fields’ ‘zoo’ These packages needs to imported from for the case when this namespace is loaded but not attached. See the information on DESCRIPTION files in the chapter ‘Creating R packages’ of the ‘Writing R Extensions’ manual. Just as packages under 'Imports:' in your DESCRIPTION file need to have corresponding import()/importFrom() statements in the NAMESPACE file, so do packages under 'Depends:'. That is what this 'R CMD check' NOTE is trying to say. If you don't do this, those package's functions/variables will only be available if you *attach* your package, but not if you only *load* it. That's also what the NOTE tries to say. When you do library()/require(), you *attach* a package and it appear in the search() path and all functions/variables in the search() path will be found by the user and from all packages attached/loaded. When a package is *loaded* - explicitly via loadNamespace()/requireNamespace(), but more commonly via Imports: statements in DESCRIPTION, it is *not* attached to the search() path and therefore none of its functions/variables are found. Such functions/variables are only found if they are explicitly imported via import()/importFrom() in the NAMESPACE file. Most people will *attach* your package, i.e. library(YourPackage), and currently the functions/variables of the packages under Depends: will be on the search() and therefore found by the functions of your package. To see what packages are attached (=on the search() path) and which are only loaded, look as sessionInfo(). So far so, good. However, if someone else decides to use one of your package's functions in their package and put it under 'Imports:, e.g. Package: AnotherPackage Depends: SomePackage Imports: YourPackage = your package you will be in trouble. Because, library(AnotherPackage) will *attach* AnotherPackage and SomePackage to the search() path and *load* YourPackage. In turn, you have specified in your DESCRIPTION will *load* all packages under its Imports: as well as Depends:. However, since your NAMESPACE file does not import()/importFrom() any of the packages under Depends:, none of those functions will be found. Your functions will give errors like 'could not find function foo. Basically, Depends: could be though of as AttachOrLoad: and Imports: as LoadOnly:. To learn more about how all this works and why/why not, I strongly recommend Suraj Gupta's nice write up 'How R Searches and Finds Stuff' (Mar 2012): http://obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/ /Henrik It is based on this line in DESCRIPTION file: Depends: fields, zoo, coda, R (= 2.14.0) I use indeed functions from fields and zoo packages. If I create a new line: Imports: fields, zoo and remove these two packages from depends, I have still a problem in Imports and errors because functions from fields and zoo are not available. * checking dependencies in R code ... NOTE Namespaces in Imports field not imported from: ‘fields’ ‘zoo’ All declared Imports should be used. See the information on DESCRIPTION files in the chapter ‘Creating R packages’ of the ‘Writing R Extensions’ manual. * checking R code for possible problems ... NOTE .read_phenology: no visible global function definition for ‘na.locf’ plot.phenologymap: no visible global function definition for ‘image.plot’ If I add the packages fields, zoo packages in both Depends and Imports, I have also error because packages fields, zoo are indicated twice and I have the same errors as previously indicated. * checking DESCRIPTION meta-information ... NOTE Packages listed in more than one of Depends, Imports, Suggests, Enhances: ‘fields’ ‘zoo’ A package should be listed in only one of these fields. Of course I read ‘Creating R packages’ of the ‘Writing R Extensions’ manual, but I can't find solution to this problem. Thanks a lot, Marc Girondot -- __ Marc Girondot, Pr Laboratoire Ecologie, Systématique et Evolution Equipe de Conservation des Populations et des Communautés CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079 Bâtiment 362 91405 Orsay Cedex, France Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1.69.15.73.53 e-mail: marc.giron...@u-psud.fr Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html Skype: girondot __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] XML package not working
Have you tried to download from another CRAN mirror, e.g. http://cran.r-project.org/web/packages/XML/ More mirrors at http://cran.r-project.org/mirrors.html As already others said, it's very unlikely that this is not an issue on your end. /Henrik On Thu, Oct 24, 2013 at 4:54 AM, Steven Dwayne Randolph randolph_steve...@lilly.com wrote: Berend Thanks. I am aware of the missing kb's in the download. However, my problem is that it only happens with this package. I download other packages manually and via command-line install.packages() and Do not have any problems with completing full downloads of the entire file. Perhaps, if someone has the complete download for the XML package, both in *.zip and *tar formats that they can either email to me or allow me to ftp from it would help me to move forward with this resolve. Thanks... Steven -Original Message- From: Berend Hasselman [mailto:b...@xs4all.nl] Sent: Tuesday, October 22, 2013 12:39 PM To: Steven Dwayne Randolph Cc: Ista Zahn; r-help@r-project.org; stevendrando...@aol.com; Piyush Singh - Network Subject: Re: [R] XML package not working On 22-10-2013, at 15:19, Steven Dwayne Randolph randolph_steve...@lilly.com wrote: Ista,... Thank you for your response. Here is what is occurring when I attempt to command-line install. -- install.packages('XML') Installing package into 'C:/Users/xxx/Documents/R/win-library/3.0' (as 'lib' is unspecified) trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.0/XML_3.98-1.1.zip' Content type 'application/zip' length 4287270 bytes (4.1 Mb) opened URL downloaded 4.1 Mb Warning in install.packages : downloaded length 4276224 != reported length 4287270 Look at what is reported here. The downloaded length is not equal to the reported (i.e. actual) length of the zip. What is the length if you download the .zip file manually? So something has gone wrong with the download. Can you open a .zip file in another program? If so see what happens if you open it in that program. You have to do detective work. Berend Warning in install.packages : error 1 in extracting from zip file Warning in install.packages : cannot open compressed file 'XML/DESCRIPTION', probable reason 'No such file or directory' Error in install.packages : cannot open the connection -- STeven -Original Message- From: Ista Zahn [mailto:istaz...@gmail.com] Sent: Tuesday, October 22, 2013 8:09 AM To: Steven Dwayne Randolph Cc: Duncan Murdoch; r-help@r-project.org; stevendrando...@aol.com; Piyush Singh - Network Subject: Re: [R] XML package not working Hi Steven, I still don't understand why you are downloading it manually. What happens when you install.packages(XML) ? Best, Ista On Tue, Oct 22, 2013 at 8:03 AM, Steven Dwayne Randolph randolph_steve...@lilly.com wrote: Duncan... Thank you. 1. I am able to download the XML file via my corporate network, other packages without this same issue, even rcurl and bitops which are pre-requisites on the same page as XML. 2. I have attempted to download this from my own wifi at home using xfinity/Comcast to my personal pc and still get the same error on this package alone. 3. I am genuinely baffled by this package download and install experience. 4. I would gladly build this from source, If indeed I could find the source and then use RTools to compile it. That has been unsuccessful as well. Nightmare? Slightly. Thanks for your response. Steven -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: Sunday, October 20, 2013 12:13 PM To: Steven Dwayne Randolph; r-help@r-project.org; Ista Zahn Cc: stevendrando...@aol.com Subject: Re: [R] XML package not working On 13-10-20 9:23 AM, Steven Dwayne Randolph wrote: My apologies for not conforming to the posting guideline. Sys.info() sysname release version Windows 7 x64 build 7601, Service Pack 1 nodename machine login xxNU247BZ1S x86-64 XX user effective_user xxxxxx When I attempt to install a local copy of the xml.zip file: in read.dcf(file.path(pkgname, DESCRIPTION), c(Package, Type)) : cannot open the connection In addition: Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In
Re: [R] Reading .gsheet within R
On Fri, Nov 30, 2012 at 9:43 AM, Luca Meyer lucam1...@gmail.com wrote: Hello R-experts, I would like to know if there is a solution to read files with extension .gsheet directly into R - see http://www.fileinfo.com/extension/gsheet for more info on this file format. AFAIK, those files (*.gsheet, *.gdoc, *.gslides) are just tiny JSON files containing references to the online/cloud resource (specifying the url and the resource_id). There are several packages on CRAN for parsing JSON files. Accessing the actual online data is a different story... My $0.02 /Henrik Thank you, Luca Mr. Luca Meyer www.lucameyer.com R 2.15.1 Mac OS X 10.8.2 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calling a .bat to set environment variables and subsequent .exe execution from within R
If all you need to do is to set environment variables, you can do that from within R, e.g. shell(echo %FOO%) %FOO% Sys.setenv(FOO=42); shell(echo %FOO%) 42 My $.02 On Sun, Dec 23, 2012 at 11:14 AM, Ludwig Hilger l.hil...@ku.de wrote: Dear list, I have found a thread dealing with similar problems with a Mac, but somehow I cannot get it to work and the problem is slightly different: I am using the shell() command to execute a program from within R. The problem is that I need to execute SDKShell.bat file first that sets the environment variables for the program ogr2ogr.exe: shell(cmd = C:\\GDAL_1.9.2_MAPSERVER_6.2.0\\SDKShell_original.bat) Setting environment for using the GDAL and MapServer tools. Hiding the OCI plugin library. D:\R_working_directory\Koordinatenproblem source(.trPaths[5], echo=TRUE, max.deparse.length=150) shell( cmd=ogr2ogr -s_srs EPSG:31254 -t_srs EPSG:25832 D:\\R_working_directory\\Koordinatenproblem\\Fliessgewaesser_25832.shp D:\\R_working_directory\\Koordinatenproblem\\Fliessgewaesser.shp, invisible = FALSE, intern = TRUE ) shell(cmd=ogr2ogr -s_srs EPSG:31254 -t_srs EPSG:25832 D:\\R_working_directory\\Koordinatenproblem\\Fliessgewaesser_25832.shp D:\\R_working_director ... ... [TRUNCATED] [1] Der Befehl \ogr2ogr\ ist entweder falsch geschrieben oder konnte nicht gefunden werden. attr(,status) [1] 1 Warnmeldung: Ausführung von Kommando 'C:\Windows\system32\cmd.exe /c ogr2ogr -s_srs EPSG:31254 -t_srs EPSG:25832 D:\R_working_directory\Koordinatenproblem\Fliessgewaesser_25832.shp D:\R_working_directory\Koordinatenproblem\Fliessgewaesser.shp' ergab Status 1 The problem is that he cmd seems to forget the result of the command before, i.e. the cmd is shut between different calls by shell()!? As a result I cannot execute ogr2ogr.exe. Is there an argument or sth. to work in the same cmd-session using subsequent shell() executions from R? Thank you, best regards and have a nice Christmas, Ludwig ps: I have also tried to rewrite the .bat to set the environment variables permanently, but I did not manage that either. - Dipl. Geogr. Ludwig Hilger Wiss. MA Lehrstuhl für Physische Geographie Katholische Universität Eichstätt-Ingolstadt Ostenstraße 18 85072 Eichstätt -- View this message in context: http://r.789695.n4.nabble.com/Calling-a-bat-to-set-environment-variables-and-subsequent-exe-execution-from-within-R-tp4653814.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 check if an attribute exists
On Wed, Feb 2, 2011 at 7:25 PM, Peter Langfelder peter.langfel...@gmail.com wrote: On Wed, Feb 2, 2011 at 7:22 PM, Nick Matzke mat...@berkeley.edu wrote: Oh wait, this basically does it: if (a %in% attributes(z)$names) + print(TRUE) [1] TRUE (but there may be a better way) If z is a list, you can test is.null(z$a) Nope, e.g. z - list(a=NULL) str(z) List of 1 $ a: NULL Instead, test by: is.element(a, names(z)) [1] TRUE or equivalently (a %in% names(z)) [1] TRUE or any(names(z) == a) [1] TRUE My $.02 /Henrik Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Write File to Shared Drive
FYI, you can use the following to troubleshoot what is going on: library(R.utils); filename - MyFile.csv; path - ... # The directory where to store pathname - Arguments$getWritablePathname(filename, path=path); or if you already have the full pathname: pathname - Arguments$getWritablePathname(pathname); You will get an informative error if something is not correct, e.g. it will check the path and report which part of the path is incorrect, it will test and report on failed write permissions etc. /Henrik On Tue, Feb 15, 2011 at 12:04 PM, Peter Langfelder peter.langfel...@gmail.com wrote: On Tue, Feb 15, 2011 at 11:56 AM, Kevin Wright kw.s...@gmail.com wrote: The original poster did not say what operating system was being used. From my own experience on Windows, I always used / for reading from the local hard drive, but when I started working with Windows network shares/folders, I had to switch back to \\ due to an unknown feature (bug?). Interesting. I have never had to use \\ instead of / on a network drive, with the caveat that I haven't used WIndows since maybe R-2.6.x. Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Weird error (special character) of read.table
On Tue, Feb 22, 2011 at 7:43 AM, John Edwards jhnedwards...@gmail.com wrote: Hi, I have the following input file. $ cat main.txt CEL_A CELL_B 1 4 2 5 2 6 Then I run read.table in R. f=read.table('main.txt', header=T, check.names=F, sep='\t') head(f) \ufeffCEL_A CELL_B 1 1 4 2 2 5 3 2 6 f$CEL_A NULL I'm not sure where the special character \ufeff comes from. Could anybody let me know what is the problem? Looks like the Unicode character called 'byte order mark' (BOM), cf. http://en.wikipedia.org/wiki/Byte_order_mark It looks like your 'main.txt' text file was created by a software that saves it as a Unicode-encoded text file. If you need a plain old-style ASCII text file, see if you can resave it as such. With last year's development in R, it also not unlikely that you can tell R to read in the existing file by specifying the encoding, but since I don't now how to do that I leave that as an search-the-help exercise for you. /Henrik Thanks, John [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing elements ..., NO bug in which() function
On Wed, Feb 23, 2011 at 1:02 PM, Martin Maechler maech...@stat.math.ethz.ch wrote: RK == Rumen Kostadinov rkost...@gmail.com on Sun, 13 Feb 2011 12:46:52 -0500 writes: RK Thanks Sarah, RK Yes, the function behaves Exactly as documented: RK check this out: a = c(1,2,3,4,5) a[which(a!=6)] RK [1] 1 2 3 4 5 a[!which(a==6)] RK numeric(0) a[-which(a==6)] RK numeric(0) a[!a==6] RK [1] 1 2 3 4 5 RK I guess this is just a gotcha, since RK I often use !which and -which to remove elements, RK So one should use RK a[which(a!=stuff to remove)] RK instead of RK a[-which(a==stuff to remove)] RK a[!which(a==stuff to remove)] BTW: you have just seen why you should *NOT* use a[ -which() ] and probably should use which() much less than you currently do. Some useRs seem overly fond of which() instead of working with the logical vectors directly ... {{Yes, I know that in some situations which() works with NAs...}} I think we (R-core) should get back to Bill Dunlap's suggestions on the R-devel list and think of providing fast functions for things like L !is.na(L) ... in other words, versions of the utilities I have in (the R package) Matrix/R/Auxiliaries.R, ## Need to consider NAs ; == 0 even works for logical complex: ## Note that !x is faster than x == 0, but does not (yet!) work for complex ## if we did these in C, would gain a factor 2 (or so): is0 - function(x) !is.na(x) x == 0 isN0 - function(x) is.na(x) | x != 0 is1 - function(x) !is.na(x) x # also == isTRUE componentwise ## all0 - function(x) !any(is.na(x)) all(!x) ## ~= allFalse any0 - function(x) isTRUE(any(x == 0)) ## ~= anyFalse ## These work identically for 1 ('==' TRUE) and 0 ('==' FALSE) ## (but give a warning for double 1 or 0) ## TODO: C versions of these would be faster allTrue - function(x) all(x) !any(is.na(x)) allFalse - function(x) !any(x) !any(is.na(x))## ~= all0 anyFalse - function(x) isTRUE(any(!x)) ## ~= any0 Note that I comment twice that it would be nice to have fast versions of these (via C). Well, at least for any(is.na(x)) there is a fast (early stopping) implementation in anyMissing(x) of the 'matrixStats' package (also in Biobase of Bioconductor). As the author I say: feel free to include it in base R. Code is available at: https://r-forge.r-project.org/scm/viewvc.php/pkg/matrixStats/?root=matrixstats See files R/anyMissing.R and src/anyMissing.c At least a start. /Henrik Martin RK On Sun, Feb 13, 2011 at 12:37 PM, Sarah Goslee sarah.gos...@gmail.com wrote: If by bug you mean function behaving exactly as documented. which() returns only the matches, the TRUE values. If there are no matches, it doesn't return anything. If I understand what you are trying to do, and I may not, a[which(a != 5)] is really what you want, and it is precisely to preserve that behavior that which() does what it does. Sarah --- which package:base R Documentation Description: Give the ‘TRUE’ indices of a logical object, allowing for array indices. Value: If ‘arr.ind == FALSE’ (the default), an integer vector with ‘length’ equal to ‘sum(x)’, i.e., to the number of ‘TRUE’s in ‘x’; Basically, the result is ‘(1:length(x))[x]’. --- On Sun, Feb 13, 2011 at 11:59 AM, Rumen Kostadinov rkost...@gmail.com wrote: Dear all, I found a bug in the which() function. When trying to remove elements with the which function, if the criteria is not matched, numeric(0) is returned instead of the array itself. This is very weird. a = c(1,2,3,4,5) a[!a==6] [1] 1 2 3 4 5 a[-which(a==6)] numeric(0) a[-which(a==5)] [1] 1 2 3 4 a[!a==5] [1] 1 2 3 4 Is this correct? I believe this is a bug. I have to rewrite a lot of my R code to use a = a[!criteria] and not a = a[-which(criteria)] R. -- Sarah Goslee http://www.functionaldiversity.org RK __ RK R-help@r-project.org mailing list RK https://stat.ethz.ch/mailman/listinfo/r-help RK PLEASE do read the posting guide http://www.R-project.org/posting-guide.html RK and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list
Re: [R] Any existing functions for reading and extracting data from path names?
Hi, the R.filesets package was designed for this. It is heavily used by the aroma framework (http://www.aroma-project.org/), so it got a fair bit of mileage now (in a good a way). Here is how you could setup your data set and work with the data. # - - - - - - - - - - - - # Setup file data set # - - - - - - - - - - - - library(R.filesets); paths - list.files(path=deleteme, full.names=TRUE); dsList - lapply(paths, FUN=function(path) TabularTextFileSet$byPath(path)); ds - Reduce(append, dsList); # Fullname translator: Los Angeles/data1.csv = Los Angeles,data1.csv setFullNamesTranslator(ds, function(name, file, ...) { path - getPath(file); paste(c(basename(path), name), collapse=,); }); # - - - - - - - - - - - - # Examples # - - - - - - - - - - - - # Get the full names (a fullname consists of # a name and comma-separated tags) getFullNames(ds) [1] Los Angeles,data1 Los Angeles,data2 [3] New York,data1 New York,data2 # Get the names getNames(ds) [1] Los Angeles Los Angeles [3] New YorkNew York ds TabularTextFileSet: Name: Los Angeles Tags: Full name: Los Angeles Number of files: 4 Names: Los Angeles, Los Angeles, New York, New York [4] Path (to the first file): deleteme/Los Angeles Total file size: 0.00 MB RAM: 0.01MB # Get 2nd file df - getFile(ds, 2) df TabularTextFile: Name: Los Angeles Tags: data2 Full name: Los Angeles,data2 Pathname: deleteme/Los Angeles/data2.csv File size: 80 bytes RAM: 0.01 MB Number of data rows: 10 Columns [2]: '', 'x' Number of text lines: 11 # Read one data file data - readDataFrame(df) data x 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 # Read all data files dataList - lapply(ds, readDataFrame) dataList $`Los Angeles,data1 x 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 $`Los Angeles,data2 x 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 $`New York,data1` x 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 $`New York,data2` x 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 Most methods in R.filesets are currently poorly documented (no time/resources/...), but there is more in there than documented so feel free to ask if you have any questions. Hope this helps /Henrik On Fri, Mar 11, 2011 at 8:52 AM, Ista Zahn iz...@psych.rochester.edu wrote: Hi helpeRs, I have inherited a set of data files that use the file system as a sort of poor man's database, i.e., the data files are nested in directories that indicate which city they come from. For example: dir.create(deleteme) for(i in paste(deleteme, c(New York, Los Angeles), sep=/)) { dir.create(i) for(j in paste(data, 1:2, .csv, sep=)) { write.csv(data.frame(x=1:10), file=paste(i, j, sep=/)) } } list.files(deleteme, recursive=TRUE) What I want to end up with is x city wave 1 New York 1 1 Los Angeles 1 1 New York 2 1 Los Angeles 2 I've started writting a simple function to do this, but it seems like a common situation and I'm wondering if there are any packages or functions that might make this easier. Thanks! Ista -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Persistent storage between package invocations
It would be nice to have a standard directory where R can write things this way. A semi-standard directory is given by Sys.getenv(R_LIBS_USER), which defaults to ~/R/.../. Maybe ~/R/ could serve as that convention? That way we (various developers etc) would also not clutter up users home directory in random ways. Personally I prefer a hidden directory, e.g. ~/.R/, but there are pros and cons with such an approach. /Henrik On Tue, Mar 15, 2011 at 8:57 AM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On Tue, 15 Mar 2011, Hadley Wickham wrote: Hi all, Does anyone have any advice or experience storing package settings between R runs? Can I rely on the user's home directory (e.g. tools::file_path_as_absolute(~)) to be available and writeable across platforms? No. First, please use path.expand(~) for this, and it does not necessarily mean the home directory (and in principle it might not expand at all). In practice I think it will always be *a* home directory, but on Windows there may be more than one (and watch out for local/roaming profile differences). Second, it need not be writeable, and so many package authors write rubbish in my home directory that I usually arrange it not be writeable to R test processes. If you want something writeable across processes, use dirname(tempdir()) . Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] This day in history: R-help, R-devel and R-announce (1997-04-01)
Today it's 16 years ago and 367,496 messages later since MartinMächler started the R-help (321,119 msgs), R-devel (45,830 msgs) and R-announce (547 msgs) mailing lists [1] - a great benefit to all of us. Special thanks to Martin and also thanks to everyone else contributing to these forums. [1] https://stat.ethz.ch/pipermail/r-help/1997-April/001490.html attachment: r-help,r-devel.png__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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: how to convert raw to numeric
See ?readBin - works also with raw objects. Henrik On Apr 3, 2013 1:18 AM, Mike Chen chenminyi1...@gmail.com wrote: I know that there is a function to convert binary data to string named rawToChar.but I wander is there any similar function for Integer and float.I need to read some binary file in integer and float data. I can do this job in this way: (as below) first convert 4 byte raw to bits then pack bits back to integer, but it not work for float,I worry about the performance. raw4 = raw_buffer[1:4] bits = rawToBits(raw4) packBits(bits, type = integer) Best wishes Really hope to get your response [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rep() fails at times=0.29*100
FYI, (0.29*100) 29 [1] TRUE See R FAQ 7.31 for why. /Henrik On Tue, Apr 9, 2013 at 9:11 AM, Jorge Fernando Saraiva de Menezes jorgefernandosara...@gmail.com wrote: Dear list, I have found an unusual behavior and would like to check if it is a possible bug, and if updating R would fix it. I am not sure if should post it in this mail list but I don't where is R bug tracker. The only mention I found that might relate to this is If times is a computed quantity it is prudent to add a small fuzz. in rep() help, but not sure if it is related to this particular problem Here it goes: rep(TRUE,29) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [28] TRUE TRUE rep(TRUE,0.29*100) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [28] TRUE length(rep(TRUE,29)) [1] 29 length(rep(TRUE,0.29*100)) [1] 28 Just to make sure: 0.29*100 [1] 29 This behavior seems to be independent of what is being repeated (rep()'s first argument) length(rep(1,0.29*100)) [1] 28 Also it occurs only with the 0.29. length(rep(1,0.291*100)) [1] 29 for(a in seq(0,1,0.01)) {print(sum(rep(TRUE,a*100)))} #also shows correct values in values from 0 to 1 except for 0.29. I have confirmed that this behavior happens in more than one machine (though I only have session info of this one) sessionInfo() R version 2.15.3 (2013-03-01) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 LC_MONETARY=Portuguese_Brazil.1252 [4] LC_NUMERIC=C LC_TIME=Portuguese_Brazil.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] spatstat_1.31-1 deldir_0.0-21 mgcv_1.7-22 loaded via a namespace (and not attached): [1] grid_2.15.3 lattice_0.20-13 Matrix_1.0-11 nlme_3.1-108 tools_2.15.3 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to transform string to Camel Case?
See for instance capitalize() in the R.utils package. Henrik On Apr 14, 2013 11:51 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all, Given the following vector: (z - c('R project', 'hello world', 'something Else')) [1] R project hello worldsomething Else I know how to obtain all capitals or all lower case letters: tolower(z) [1] r project hello worldsomething else toupper(z) [1] R PROJECT HELLO WORLDSOMETHING ELSE I saw the tocamel() function in 'rapport', but it doesn't do what I want to achieve as it actually proceeds to camelCase/CamelCase the strings: tocamel(z) [1] RProject helloWorldsomethingElse But how should I proceed to obtain Camel Case? Here's what I'd like to get: c('R Project', 'Hello World', 'Something Else') Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] texi2pdf texinputs arguments
I'm pretty sure the intended design is to always use the current working directory as the output directory, cf. 'Value' section in help(texi2dvi, package=tools): Used for the side effect of creating a dvi or PDF file in the current working directory (and maybe other files, especially if clean = FALSE). So, use setwd() before calling texi2dvi() if you like a different directory. /Henrik On Thu, Apr 18, 2013 at 3:23 PM, Duncan Mackay mac...@northnet.com.au wrote: Dear All I am trying to specify the output directory and the directory for the log files (the same) for texi2dvi. The default for my windows computer is C:\Users\...\Documents which I do not want. The help guide: texinputs NULL or a character vector of paths to add to the LaTeX and bibtex input search paths. is a little cryptic for me this morning I have tried texi2dvi(file = d:/Cic/Sweave/Figs/Sheep3/FS/14/sFSheepFS14.tex, pdf=TRUE,clean=F, texinputs = --include-directory=d:/Cic/Sweave/Figs/Sheep3/FS/14) and other variants Any guide on how to specify the output directory would be greatly appreciated. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R CMD build
On Sat, Apr 20, 2013 at 3:10 PM, Knut Krueger r...@knut-krueger.de wrote: Am 20.04.2013 15:50, schrieb Gabor Grothendieck: Note that there is a separate directory for the 64-bit R executables. Does it make any difference to check and pack the source files iwth 32 or 64 bit? Also, downloading MinGW should not be needed. Rtools already contains the needed UNIX utilities. Yes indeed it works better than MinGW You might want to look into the Windows batch files at http://batchfiles.googlecode.com . At least it would be very helpful for windows user to give the hint to the executable rcmd.exe build ... instead of R cmd build ... FYI, R CMD build ... works just fine on Windows (and I'm sure R cmd build ... won't). /Henrik I already set up an linux system today to solve the problem Thank you Knut __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 7 arguments passed to .Internal(identical) which requires 6
FYI, whenever getting an error, run traceback() *immediately after* (i.e. before any other commands) and include that in your error report. Also include the output of sessionInfo(). It helps tremendously and spares lots of second guessing. /Henrik On Wed, Apr 11, 2012 at 8:28 AM, krtek marshal...@mail.ru wrote: Thank you! Updating to R-patched really helped me. My problem were not been into my code. I've tried to run source() and the error had occurred again. I didn't use a mixture of different versions of R, version 2.13.2 has been deleted. -- View this message in context: http://r.789695.n4.nabble.com/7-arguments-passed-to-Internal-identical-which-requires-6-tp4548460p4549183.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Organizations where IT has approved the use of R software
May be of use too: The R Foundation for Statistical Computing, R: Regulatory Compliance and Validation Issues - A Guidance Document for the Use of R in Regulated Clinical Trial Environments, August 17, 2008 [http://www.r-project.org/certification.html] /Henrik On Thu, Apr 12, 2012 at 1:06 PM, Thomas Adams thomas.ad...@noaa.gov wrote: All: R is used by the NOAA/U.S. National Weather Service to generate graphics representing real-time hydrologic ensemble (probabilistic) forecasts. Go to: http://www.erh.noaa.gov/mmefs/ to see. It is also used in research and development for forecast verification and analyses for the calibration of distributed hydrologic models. Tom On Thu, Apr 12, 2012 at 3:52 PM, David Smith da...@revolutionanalytics.comwrote: It's hard to respond without making it seem like an advertisement for Revolution Analytics, but helping companies and government organizations standardize on R (specifically, Revolution R) for data analysis is something we specialize in. The (partial) list of our customers using Revolution R at http://www.revolutionanalytics.com/aboutus/our-customers.php may be useful fodder for your IT group, as may be this list of applications companies have done with R: http://www.revolutionanalytics.com/what-is-open-source-r/companies-using-r.php The section on the Revolutions blog that Michael Weylandt pointed to (http://blog.revolutionanalytics.com/applications/) may also be useful to you. If you'd like to contact me directly, I'd be happy to connect you with some folks here at Revolution Analytics that can provide direct help on getting R adopted at your organization. Hope this is useful to you, # David Smith On Thu, Apr 12, 2012 at 11:04, lynnland lynn.landria...@ontario.ca wrote: Hi Gang, I realize this post is not directly related to programing issues with R, however, it appears this may be the best place to ask my question. I am putting forward a request that R be considered approved software in my organization. Never an easy task, this is made much more difficult given that it is open source software (sends the IT gang into little fits). So, I am compiling a list of organizations (Universities, goverment, industry,etc.) that are using R and whose IT department considers it approved software. If you belong to such an organization could you please let me know? If you know of organizations that this applies to, but are not directly affiliated with them I would still be interested but please just let me know which of these two cases your response fits into. Thanks in advance. Lynn -- David M Smith da...@revolutionanalytics.com VP of Marketing, Revolution Analytics http://blog.revolutionanalytics.com Tel: +1 (650) 646-9523 (Palo Alto, CA, USA) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Thomas E Adams National Weather Service Ohio River Forecast Center 1901 South State Route 134 Wilmington, OH 45177 EMAIL: thomas.ad...@noaa.gov VOICE: 937-383-0528 FAX: 937-383-0033 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can a matrix have 'list' as rows/columns?
On Mon, Apr 16, 2012 at 9:13 PM, Worik R wor...@gmail.com wrote: After a lot of processing I get a matrix into M. I expected each row and column to be a vector. But it is a list. Lists are also vectors, e.g. x - list() is.vector(x) [1] TRUE y - vector(list, length=3) str(y) List of 3 $ : NULL $ : NULL $ : NULL See ?list /HB R-Inferno says... Arrays (including matrices) can be subscripted with a matrix of positive numbers. The subscripting matrix has as many columns as there are dimensions in the array—so two columns for a matrix. The result is a vector (not an array) containing the selected items. My version of R: version.string R version 2.12.1 (2010-12-16) Here is an example... Qm - c(aaa, bbb, ccc) DF - data.frame(Name=sample(Qm, replace=TRUE, size=22), Value=runif(22), stringsAsFactors=FALSE) M - sapply(Qm, function(nm, DF){last(DF[DF[, Name]==nm,])}, DF) class(M) [1] matrix class(M[,1]) [1] list class(M[1,]) [1] list M aaa bbb ccc Name aaa bbb ccc Value 0.4702648 0.274498 0.5529691 DF Name Value 1 ccc 0.99948920 2 aaa 0.51921281 3 aaa 0.10803943 4 aaa 0.82265847 5 ccc 0.83237260 6 bbb 0.88250933 7 aaa 0.41836131 8 aaa 0.66197290 9 ccc 0.01911771 10 ccc 0.4699 11 bbb 0.35719884 12 ccc 0.86274858 13 bbb 0.57528579 14 aaa 0.12452158 15 aaa 0.44167731 16 aaa 0.11660019 17 ccc 0.55296911 18 aaa 0.12796890 19 bbb 0.44595741 20 bbb 0.93024768 21 aaa 0.47026475 22 bbb 0.27449801 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error with Rcmd check library --as-cran
paleotree imports phangorn which depends on Matrix, so your example does indeed depend on Matrix. A possible reason is that your installed Matrix was built for a different version of R, i.e. check packageDescription(Matrix). /Henrik On Tue, Apr 17, 2012 at 4:23 PM, David Bapst dwba...@uchicago.edu wrote: Hello all, I was checking the newest update of my library before submitting it to CRAN, using R 2.15.0 and Rtools for Windows 215 using Rcmd in the Command Prompt, on my x64 Windows7 laptop. I recently heard that for checking packages for CRAN submission one should use the option --as-cran; previously I was submitting packages, so I was trying that for the first time. The check proceeds fine until it tries running the examples, at which point it produces the following error message: pkgname - paleotree source(file.path(R.home(share), R, examples-header.R)) options(warn = 1) options(pager = console) library('paleotree') Loading required package: ape Error in loadNamespace(i, c(lib.loc, .libPaths())) : there is no package called 'Matrix' Error: package/namespace load failed for 'paleotree' Execution halted My package depends on ape, but not Matrix. Matrix is installed, though, on my workstation, as are the other ape dependencies. The check works fine by default and with the --timings option. What is different about --as-cran that makes it unable to find Matrix? Thanks for the help, -Dave Bapst, UChicago -- David Bapst Dept of Geophysical Sciences University of Chicago 5734 S. Ellis Chicago, IL 60637 http://home.uchicago.edu/~dwbapst/ http://cran.r-project.org/web/packages/paleotree/index.html http://home.uchicago.edu/%7Edwbapst/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] load only one object from a .RData file
You could do: library(R.utils); value - loadToEnv(MyFile.RData)[[nameOfObject]]; It still load all of the data, but it is not kept; only the object you grab. /Henrik On Tue, Apr 24, 2012 at 11:30 AM, Shi, Tao shida...@yahoo.com wrote: Hi list, Is there a way to load one specific object from a .RData file which contains multiple data objects? Thanks, ...Tao __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ErrError in f(x, ...) : object 'g.' not found
If it helps... R is not Matlab. There is no '.*' operator in R. /H On Thu, Apr 26, 2012 at 2:37 PM, Sarah Goslee sarah.gos...@gmail.com wrote: On Thu, Apr 26, 2012 at 5:34 PM, Guaramy _ guar...@hotmail.com wrote: Thanks for your answer, but how can i correct that, the mathematical expression is correct that way with that g. Do you know how can i program it ? Then you need to define g. and how it differs from g alone. g. and g are two separate objects in R. Sarah PS You also need to convert your email program to plain text, or whatever caused the horrid formatting below. Date: Thu, 26 Apr 2012 13:57:36 -0400 Subject: Re: [R] ErrError in f(x, ...) : object 'g.' not found From: sarah.gos...@gmail.com To: guar...@hotmail.com CC: r-help@r-project.org Just what it says: You define g but refer to a variable g. in the next line. Just get rid of the typo. Sarah On Thu, Apr 26, 2012 at 1:43 PM, Guaramy guar...@hotmail.com wrote: Hi , R is a new language for me so sorry in advance if this error is to basic for posting. I have tried the R manual and search online for quite a few, if anyone could help i would be very thankful. Here is ámy code. kappa = 1.1 theta = 0.1 sigma = 0.4 rho = -0.6 v0 = 0.2 r = 0.05 T = 0.5 s0 = 1 K = 0.5 type = 1 Hestoncall = function(kappa,theta,sigma,rho,v0,r,T,s0,K,type) { á á á á á á á á á á á á á á á á u = 0.5 á á á á á á á á á á á á á á á á b = kappa-rho*sigma á á á á á á á á á á á á á á á á a = kappa*theta á á á á á á á á á á á á á á á á x = log(s0) á á á á á á á áHestf = function(phi) á á á á á á á á{ á á á á á á á á á á á á á á á á d = sqrt((b-rho*sigma*phi*complex(1,0,1)-b )^2-sigma^2*(2*u*phi^2)) á á á á á á á á á á á á á á á á g = (b-rho*sigma*phi*complex(1,0,1)+d)/(b-rho*sigma*phi*complex(1,0,1)-d) á á á á á á á á á á á á á á á á C = r*phi*complex(1,0,1)*T + a/sigma^2*((b-rho*sigma*phi*complex(1,0,1)+d)*T-2*log((1-g.*exp(d*T))/(1-g))) á á á á á á á á á á á á á á á á D = (b-rho*sigma*phi*complex(1,0,1)+d)/sigma^2*((1-exp(d*T))/(1-g*exp(d*T))) á á á á á á á á á á á á á á á á f = exp(C+D*v0 +complex(1,0,1)*phi*x); á á á á á á á á á á á á áHestonPintegrand á= real (exp(-1i*phi*log(K))*f/(1i*phi)) á á á á á á á á á á á á áHestonPintegrand á á á á á á á á á á á á} á á á á #int.fn = function(t){sapply(t,FUN=Hestf)} á á á á IH = integrate(Hestf,lower=0,upper=Inf,rel.tol=1e-10,subdivisions=100) á á á á ret = 0.5 + 1/pi*IH á á á ácall = s0*ret - K*exp(r-T)*ret á á á ácall } thanks in advance -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Memoize and vectorize a custom function
On Thu, Apr 26, 2012 at 3:21 PM, Kamil Slowikowski kslowikow...@gmail.com wrote: My goal is simple: calcuate GC content of each sequence in a list of nucleotide sequences. I have figured out how to vectorize, but all my attempts at memoization failed. Can you show me how to properly memoize my function? There is a StackOverflow post on the subject of memoization, but it does not help me: http://stackoverflow.com/questions/7262485/options-for-caching-memoization-hashing-in-r I haven't been able to find any other discussions on this subject. Searching for memoise or memoize on r-bloggers.com returns zero results. Searching for those keywords at http://r-project.markmail.org/ does not return helpful discussions. Here's my data: seqs - c(,G,C,CCC,T,,TTCCT,,C,CTC) Some sequences are missing, so they're blank ``. I have a function for calculating GC content: GC - function(s) { if (!is.character(s)) return(NA) n - nchar(s) if (n == 0) return(NA) m - gregexpr('[GCSgcs]', s)[[1]] if (m[1] 1) return(0) return(100.0 * length(m) / n) } It works: GC('') [1] NA GC('G') [1] 100 GC('GAG') [1] 66.7 sapply(seqs, GC) G C CCC T TTCCT C NA 100.0 100.0 100.0 0.0 NA 40.0 NA 100.0 CTC 66.7 I want to memoize it. Then, I want to vectorize it. Should be easy, right? Apparently, I must have the wrong mindset for using the `memoise` or `R.cache` R packages: system.time(dummy - sapply(rep(seqs,100), GC)) user system elapsed 0.044 0.000 0.054 library(memoise) GCm1 - memoise(GC) system.time(dummy - sapply(rep(seqs,100), GCm1)) user system elapsed 0.164 0.000 0.173 library(R.cache) GCm2 - addMemoization(GC) system.time(dummy - sapply(rep(seqs,100), GCm2)) user system elapsed 10.601 0.252 10.926 Notice that the memoized functions are several orders of magnitude slower. About R.cache: All memoization by R.cache is currently done toward the file system. In other words, it is designed for larger objects (so you cannot hold all of the cache in memory) and more computationally expensive tasks. /Henrik I tried the `hash` package, but things seem to be happening behind the scenes and I don't understand the output: cache - hash() GCc - function(s) { if (!is.character(s) || nchar(s) == 0) { return(NA) } if(exists(s, cache)) { return(cache[[s]]) } result - GC(s) cache[[s]] - result return(result) } sapply(seqs,GCc) [[1]] [1] NA $G [1] 100 $C NULL $CCC [1] 100 $T NULL [[6]] [1] NA $TTCCT [1] 40 [[8]] [1] NA $C NULL $CTC [1] 66.7 At least I figured out how to vectorize: GCv - Vectorize(GC) GCv(seqs) G C CCC T TTCCT C 0.0 100.0 100.0 100.0 0.0 0.0 40.0 0.0 100.0 CTC 66.7 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Quickest way to make a large empty file on disk?
An R solution is: allocateFile - function(pathname, nbrOfBytes) { con - file(pathname, open=wb); on.exit(close(con)); seek(con, where=nbrOfBytes-1L, origin=start, rw=write); writeBin(as.raw(0), con=con); invisible(pathname); } # allocateFile() allocateFile(foo.bin, nbrOfBytes=985403) file.info(foo.bin)$size [1] 985403 Note sure if it works on all OSes/file systems. /Henrik On Wed, May 2, 2012 at 3:23 PM, Jonathan Greenberg j...@illinois.edu wrote: R-helpers: What would be the absolute fastest way to make a large empty file (e.g. filled with all zeroes) on disk, given a byte size and a given number number of empty values. I know I can use writeBin, but the object in this case may be far too large to store in main memory. I'm asking because I'm going to use this file in conjunction with mmap to do parallel writes to this file. Say, I want to create a blank file of 10,000 floating point numbers. Thanks! --j -- Jonathan A. Greenberg, PhD Assistant Professor Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 607 South Mathews Avenue, MC 150 Urbana, IL 61801 Phone: 415-763-5476 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007 http://www.geog.illinois.edu/people/JonathanGreenberg.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] download extremely slow
On Sat, May 5, 2012 at 2:10 PM, Hillary Sardiñas herongr...@gmail.com wrote: I have been trying to download the latest version to my Macbook X version 10.6.8 from my institutions mirror http://cran.cnr.Berkeley.edu Usually is only takes minutes, but regardless of the browser or where I connect to the internet I have been unable to download because it would take upwards 2 days according to the download dialogue box. I'd really like to get the newest version to run some new packages that don't seem to work well in what I have currently (2.12.1) I had the same problem last time I tried to update ~ 3 weeks ago. Who should I contact/what should I do? You can always try another CRAN mirror. But it doesn't look like a problem with the Berkeley CRAN server: wget http://cran.cnr.berkeley.edu/bin/macosx/leopard/base/R-latest.pkg % Total% Received % Xferd Average Speed TimeTime Time Current Dload Upload Total SpentLeft Speed 100 64.1M 100 64.1M0 0 11.1M 0 0:00:05 0:00:05 --:--:-- 11.1M Most likely something with your computer. /Henrik Thanks! -- Hillary Sardiñas PhD Candidate Environmental Science, Policy Management University of California, Berkeley http://nature.berkeley.edu/kremenlab/hillary.html There is only one question: how to love this world. ~ Mary Oliver [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to download source code, pdf manual for any package from internet?
You need to specify that you want a binary download - make sure to read help(download.file), particular that of argument 'mode'. Alternatively, use downloadFile() in the R.utils package which download as binary by default. /Henrik On Sat, May 19, 2012 at 7:22 AM, sagarnikam123 sagarnikam...@gmail.com wrote: i use download.file() ,it works good for package source code t-available.packages(type=source) #all packages(list) from repository in source code .tar.gz format length(t[,2]) #total packages-- 3796 #package source file download for( i in seq_along(t[,1]) ) { download.file( paste(t[i,Repository],/,t[i,Package],_,t[i,Version],.tar.gz,sep=),destfile=paste(C:/Users/exam.2-235/Documents/R_laveria/,t[i,Package],_,t[i,Version],.tar.gz,sep=) ) } #package pdf downloading for(j in seq_along(t[,1]) ){ download.file( paste(http://cran.r-project.org/web/packages/,t[j,Package],/,t[j,Package],.pdf,sep=;),destfile=paste(C:/Users/exam.2-235/Documents/R_rab/,t[j,Package],.pdf,sep=) ) } when i am trying for pdf ,it downloads completely, but when open in pdf reader,it tell that pdf cannot be open because it's damaged cannot be repaired what will be problem ? i am working on windows-vista -- View this message in context: http://r.789695.n4.nabble.com/how-to-download-source-code-pdf-manual-for-any-package-from-internet-tp4630354p4630600.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Median computation
See rowMedians() of the matrixStats package for replacing apply(x, MARGIN=1, FUN=median). /Henrik On Tue, May 22, 2012 at 12:34 PM, Preeti pre...@sci.utah.edu wrote: Hi, I have a 250,000 by 300 matrix. I am trying to calculate the median of those columns (by row) with column names that are identical. I would like this to be efficient since apply(x,1,median) where x is created by choosing only those columns with same column name and looping on this is taking a really long time. Is there an efficient way to do this? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Median computation
Just adding a few cents to this: rowMedians(x) is roughly 4-10 times faster than apply(x, MARGIN=1, FUN=median) - at least on my local Windows 7 64bit tests. You can do these simple benchmark runs yourself via the matrixStats/tests/rowMedians.R system test, cf. http://goo.gl/YCJed [R-forge]. /Henrik On Wed, May 23, 2012 at 10:30 AM, Preeti pre...@sci.utah.edu wrote: Hmm.. that is interesting... I did this on our server machine which has about 200 cores. So memory is not an issue. Also, building the dataframe takes about a few minutes maximum for me. My code is similar to yours but for the fact that I create my dataframe from read.delim(filename) and then I drop the first column because it has characters. I don't know why it takes long on my machine. On Wed, May 23, 2012 at 11:26 AM, Benno Pütz pu...@mpipsykl.mpg.de wrote: I wonder how you do this (or maybe on what kind of machine you execute it). I tried it out of curiosity and get df = as.data.frame(lapply(1:300,function(x)sample(200,25,T))) colnames(df) = sample(letters[1:20],300,T) system.time(dfmed-lapply(unique(colnames(df)), function(x) + rowMedians(as.matrix(df[,colnames(df) == x]),na.rm=TRUE))) user system elapsed 5.680 0.952 7.171 and those times are in seconds! The time consuming part was building the data.frame not the calculation. The only thing I noticed is that my R process claims some 1.4 GB of memory but that should not be a problem on any recent hardware but my guess at answering your question would be that this might be your problem, especially if you have other memory-hogging variables like this data frame lying around and you see severe memory swapping effects Benno Hello Everybody, The code: dfmed-lapply(unique(colnames(df)), function(x) rowMedians(as.matrix(df[,colnames(df) == x]),na.rm=TRUE)) takes really long time to execute ( in hours). Is there a faster way to do this? Thanks! On Tue, May 22, 2012 at 3:46 PM, Preeti pre...@sci.utah.edu wrote: Thanks Henrik! Here is the one-liner that I wrote: dfmed-lapply(unique(colnames(df)), function(x) rowMedians(as.matrix(df[,colnames(df) == x]),na.rm=TRUE)) Thanks again! On Tue, May 22, 2012 at 3:23 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: See rowMedians() of the matrixStats package for replacing apply(x, MARGIN=1, FUN=median). /Henrik On Tue, May 22, 2012 at 12:34 PM, Preeti pre...@sci.utah.edu wrote: Hi, I have a 250,000 by 300 matrix. I am trying to calculate the median of those columns (by row) with column names that are identical. I would like this to be efficient since apply(x,1,median) where x is created by choosing only those columns with same column name and looping on this is taking a really long time. Is there an efficient way to do this? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Benno Pütz Statistical Genetics MPI of Psychiatry Kraepelinstr. 2-10 80804 Munich, Germany T: ++49-(0)89-306 22 222 F: ++49-(0)89-306 22 601 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing many csv files into separate matrices
On Wed, Dec 4, 2013 at 6:53 PM, Greg Snow 538...@gmail.com wrote: As you have noticed, using assign is not simple, and your approach has potential to cause even more problems even if you get it working. Here is another approach: loadCSVfiles - function(path) { x - list.files(path, full.names=TRUE) out - lapply( x, read.csv ) names(out) - sub(pattern=\\.csv$, replacement=, x) out } then run: mydata - loadCSVfiles(/my/path) I fully agree with this; instead of messing around with assign() - ending up using assign() is often a good indicator that there is another better way to do it. BTW, read.csv() returns a data.frame (not a matrix) just as read.table() do. An alternative to the above loadCSVfiles() function, is to use the R.filesets package, e.g. library(R.filesets) ds - TabularTextFileSet$byPath(/my/path, pattern=[.]csv$) mydata - lapply(ds, FUN=readDataFrame) That also sets the names by the filenames w/out the extension. If one don't like that style, the same thing can be achieved by: library(R.filesets) files - dir(path=/my/path, pattern=[.]csv$, full.names=TRUE) mydata - readDataFrame(files, combineBy=NULL) /Henrik and mydata will be a list with all of your data objects with the desired names. You can do things like: plot(mydata$alaska) or with(mydata, plot(alaska)) or lapply( mydata, plot ) etc. This approach does not place the individual objects into the global workspace, but that is a good thing. On Wed, Nov 27, 2013 at 3:39 PM, yetik serbest yserb...@prodigy.net wrote: Hi Everyone, I am trying to import many CSV files to their own matrices. Example, alaska_93.csv to alaska. When I execute the following, for each csv.file separately it is successful. singleCSVFile2Matrix - function(x,path) { assign(gsub(pattern=.csv,x,replacement=),read.csv(paste(path,x,sep=))) } when I try to include it in a loop in another function (I have so many csv files to import), it doesn't work. I mean the following function doesn't do it. loadCSVFiles_old - function(path) { x - list.files(path) for (i in 1:length(x)) { assign(gsub(pattern=.csv,x[i],replacement=),read.csv(paste(path,x[i],sep=))) } } Instead, if I execute the foor loop in the command line, it works. I am puzzled. Appreciate any help. thanks yetik __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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: C stack usage is too close to the limit when using list.files()
FYI, in R.utils (= 1.28.4) you can use listDirectory() to control how deep the recursion goes, which would give you protection against your problem, e.g. R.utils::listDirectory(dir, recursive=5L) where recursive=0L is equivalent to recursive=FALSE. Using recursive=TRUE corresponds to recursive=+Inf, that is infinite depth. listDirectory() accepts similar arguments that list.files() does. /Henrik On Sat, Sep 28, 2013 at 5:06 PM, William Dunlap wdun...@tibco.com wrote: The issue is not symbolic links per se, but ones that form loops. Note that you can detect such loops by running 'find -L ...' and looking for the error messages. (find by default does not follow any symbolic links, which can be a problem also.) It is a shortcoming of the current version of list.files(). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: jgrn...@gmail.com [mailto:jgrn...@gmail.com] On Behalf Of Jonathan Greenberg Sent: Saturday, September 28, 2013 10:51 AM To: William Dunlap Cc: r-help Subject: Re: [R] Error: C stack usage is too close to the limit when using list.files() Thanks all -- ok, so the symbolic link issue is a distinct possibility, but fundamentally doesn't solve the issue since most users will have symbolic links on their machines SOMEPLACE, so a full drive scan will run into these issues -- is list.files calling find, or is it using a different algorithm? This seems like a shortcoming in the list.files algorithm -- is there a better solution (short of a System call, which I'm still not sure will work on Macs without Xcode -- a colleague of mine did NOT have Xcode, and reported not being able to run find from the command line) -- perhaps a different package? --j On Fri, Sep 27, 2013 at 3:08 PM, William Dunlap wdun...@tibco.com wrote: Toss a couple of extra files in there and you will see the output grow exponentially. % touch dir/IMPORTANT_1 dir/subdir/IMPORTANT_2 and in R those two new files cause 82 more strings to appear in list.file's output: nchar(list.files(dir, recursive=TRUE)) [1] 11 18 33 40 55 62 77 84 99 106 121 128 143 150 165 172 187 194 209 [20] 216 231 238 253 260 275 282 297 304 319 326 341 348 363 370 385 392 407 414 [39] 429 436 451 458 473 480 495 502 517 524 539 546 561 568 583 590 605 612 627 [58] 634 649 656 671 678 693 700 715 722 737 744 759 766 781 788 803 810 825 832 [77] 847 854 869 876 891 898 901 'find', by default, does not following symbolic links. % find dir dir dir/subdir dir/subdir/IMPORTANT_2 dir/subdir/linkToUpperDir dir/IMPORTANT_1 The -L option makes it follow them, but it won't follow loops: % find -L dir dir dir/subdir dir/subdir/IMPORTANT_2 find: File system loop detected; `dir/subdir/linkToUpperDir' is part of the same file system loop as `dir'. dir/IMPORTANT_1 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap Sent: Friday, September 27, 2013 12:56 PM To: Jonathan Greenberg; r-help Subject: Re: [R] Error: C stack usage is too close to the limit when using list.files() Do you have some symbolic links that make loops in your file system? list.files() has problems with such loops and find does not. E.g., on a Linux box: % cd /tmp % mkdir dir dir/subdir % cd dir/subdir % ln -s ../../dir linkToUpperDir % cd /tmp % R --quiet list.files(dir, recursive=TRUE, full=TRUE) [1] dir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToU pperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkT oUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/li nkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdi r/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/su bdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir /subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpper Dir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUp perDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkTo UpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir/subdir/lin kToUpperDir/subdir/linkToUpperDir/subdir/linkToUpperDir system(find dir) dir dir/subdir dir/subdir/linkToUpperDir Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Greenberg Sent: Friday, September 27, 2013 12:13 PM To: r-help Subject: [R] Error: C stack usage is too close to the limit when using
Re: [R] Exporting R graphics into Word without losing graph quality
See ?png and argument 'pointsize'. You can increase that as you increase the dimensions of the output image. /Henrik On Sun, Dec 15, 2013 at 3:00 PM, david hamer j.david.ha...@gmail.com wrote: Hello, My x-y scatterplot produces a very ragged best-fit line when imported into Word. * plot (data.file$x, data.file$y, type = p, las=1, pch=20,ylab = expression(Cover of Species y ~ (m^{2}~ha^{-1} )),xlab = expression(Cover of Species x ~ (m^{2}~ha^{-1})) )lines ( data.file$x, fitted ( model.x ) )* A suggestion from the internet is to use .png at high (1200) resolution. * dev.print ( device = png, file = R.graph.png, width = 1200, height = 700)* This gives a high–quality graph, but the titles and tick–mark labels become very tiny when exported into Word. I therefore increased the size of the titles and tick–mark labels with cex. * plot (..cex =1.8, cex.lab = 1.8, cex.axis = 1.25,)* But this causes the x–axis title to lie on top of the tick–mark labels. (This problem does not occur with the y–axis, where the title lies well away from the y–axis tick–mark labels.) Changing margins * par ( mai = c ( 1.3, 1.35, 1, .75 ) )*does not seem to have any effect on this. A suggestion from the internet is to delete the titles from plot, and use mtext with line=4 to drop the title lower on the graph. * plot (... ylab = , xlab = .)mtext(side = 1, Cover of Species x (superscripts??), line = 4)* This works, but with mtext I have now lost the ability to have the superscripts in the axis title. And I am back full circle, having to lower the resolution of the graph to keep the x–axis title away from the axis, and thus reverting to a ragged, segmented “line” when exported to Word.. Final note: The R graphics window version of the graph becomes very distorted, even though the graph may be of high quality (other than the problem of the x-axis title overlaying the x-axis tick-mark labels) once in Word. I guess this is because of using “tricks” to try to get a desired end-product in Word Thanks for any suggestions, David. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Exporting R graphics into Word without losing graph quality
And possibly better, argument 'res', e.g. png(R.graph.png, width=1200, height = 700, res=144) plot(...) dev.off() Default corresponds to res=72. /Henrik On Sun, Dec 15, 2013 at 3:13 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: See ?png and argument 'pointsize'. You can increase that as you increase the dimensions of the output image. /Henrik On Sun, Dec 15, 2013 at 3:00 PM, david hamer j.david.ha...@gmail.com wrote: Hello, My x-y scatterplot produces a very ragged best-fit line when imported into Word. * plot (data.file$x, data.file$y, type = p, las=1, pch=20,ylab = expression(Cover of Species y ~ (m^{2}~ha^{-1} )),xlab = expression(Cover of Species x ~ (m^{2}~ha^{-1})) )lines ( data.file$x, fitted ( model.x ) )* A suggestion from the internet is to use .png at high (1200) resolution. * dev.print ( device = png, file = R.graph.png, width = 1200, height = 700)* This gives a high–quality graph, but the titles and tick–mark labels become very tiny when exported into Word. I therefore increased the size of the titles and tick–mark labels with cex. * plot (..cex =1.8, cex.lab = 1.8, cex.axis = 1.25,)* But this causes the x–axis title to lie on top of the tick–mark labels. (This problem does not occur with the y–axis, where the title lies well away from the y–axis tick–mark labels.) Changing margins * par ( mai = c ( 1.3, 1.35, 1, .75 ) )*does not seem to have any effect on this. A suggestion from the internet is to delete the titles from plot, and use mtext with line=4 to drop the title lower on the graph. * plot (... ylab = , xlab = .)mtext(side = 1, Cover of Species x (superscripts??), line = 4)* This works, but with mtext I have now lost the ability to have the superscripts in the axis title. And I am back full circle, having to lower the resolution of the graph to keep the x–axis title away from the axis, and thus reverting to a ragged, segmented “line” when exported to Word.. Final note: The R graphics window version of the graph becomes very distorted, even though the graph may be of high quality (other than the problem of the x-axis title overlaying the x-axis tick-mark labels) once in Word. I guess this is because of using “tricks” to try to get a desired end-product in Word Thanks for any suggestions, David. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] seq_len and loops
What about seq_len2 - function(length.out, from=1L) { seq(from=from, length.out=max(0L, length.out-from+1L)) } lapply(0:4, FUN=seq_len2, from=2L) [[1]] integer(0) [[2]] integer(0) [[3]] [1] 2 [[4]] [1] 2 3 [[5]] [1] 2 3 4 /Henrik On Sat, Dec 21, 2013 at 2:57 PM, Göran Broström goran.brost...@umu.se wrote: I was recently reminded on this list that Using 1:ncol() is bad practice (seq_len is designed for that purpose) (Ripley) This triggers the following question: What is good practice for 2:ncol(x)? (This is not a joke; in a recursive situation it often makes sense to perform the calculation for the start value i = 1, then continue with a loop over the rest, the Fortran way;) I usually use if (ncol(x) 1) for (i in 2:ncol(x)){ but I can think of for (i in seq_len(x - 1)){ I - i + 1 and i - 1 while (i ncol(x)){ i - i + 1 What is good practice (efficient and safe)? Göran Broström __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unable to Install a package from source in Windows
The answer most likely is in the message: '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. That path starting with a \\ is a *UNC path* (a Windows thing), which I believe install.packages() cannot install to. If you look at the output of: .libPaths() you'll probably find that the first entry contains the above path (I think). I'm pretty sure there is a non-UNC path to your user home directory, e.g. C:\Users\rvaradh1 or just H:, but currently the system environment variable HOME points to '\\homer.win.ad.jhu.edu\users$\rvaradh1\, cf. Sys.getenv(HOME), which is used by default to set .libPaths(). However, you can control it by setting R_LIBS or R_LIBS_USER to avoid a UNC path, cf ?.libPaths. Also, you may want to tell your sysadm to change HOME to a non-UNC path (which is a bit odd). In the worst case scenario, you can try to map the UNC path to a drive letter and change .libPaths() accordingly, e.g. # Assuming the first lib path is the problematic one: path - .libPaths()[1] # Map to drive letter Z system2(net, args=c(use, Z:, path)) # Update so that packages are installed to that directory .libPaths(Z:/) Then retry to install... If you don't understand the above, talk to your sysadm. /Henrik On Thu, Jan 9, 2014 at 8:46 AM, Ravi Varadhan ravi.varad...@jhu.edu wrote: Hi, I am using following R version: version _ platform i386-w64-mingw32 arch i386 os mingw32 system i386, mingw32 status major 3 minor 0.1 year 2013 month 05 day16 svn rev62743 language R version.string R version 3.0.1 (2013-05-16) nickname Good Sport I was able to build the source of a package without any errors or warnings. However, when I try to install the package, I get the following error messages. Can someone point me to what I am doing wrong? Thanks in advance, Ravi install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, repos=NULL, type=source) Installing package into '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0' (as 'lib' is unspecified) '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. * installing *source* package 'BB' ... ** R ** demo ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices ** building package indices ** installing vignettes ** testing if installed package can be loaded *** arch - i386 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted *** arch - x64 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted ERROR: loading failed for 'i386', 'x64' * removing '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' * restoring previous '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' Warning messages: 1: running command 'C:/PROGRA~1/R/R-30~1.1/bin/i386/R CMD INSTALL -l \\homer.win.ad.jhu.edu\users$\rvaradh1\Documents\R\win-library\3.0 H:/Documents/computations/BB_2014.01-1.tar.gz' had status 1 2: In install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, : installation of package 'H:/Documents/computations/BB_2014.01-1.tar.gz' had non-zero exit status [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unable to Install a package from source in Windows
On Thu, Jan 9, 2014 at 11:04 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: The answer most likely is in the message: '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. That path starting with a \\ is a *UNC path* (a Windows thing), which I believe install.packages() cannot install to. Actually, that particular message appears because your *current working directory* (getwd()) is a UNC path. So, you must make sure to call install.packages() with a regular working directory. However, even if you still do this, I believe install.packages() will give another error related to the UNC path. My $.02+$.02 /H If you look at the output of: .libPaths() you'll probably find that the first entry contains the above path (I think). I'm pretty sure there is a non-UNC path to your user home directory, e.g. C:\Users\rvaradh1 or just H:, but currently the system environment variable HOME points to '\\homer.win.ad.jhu.edu\users$\rvaradh1\, cf. Sys.getenv(HOME), which is used by default to set .libPaths(). However, you can control it by setting R_LIBS or R_LIBS_USER to avoid a UNC path, cf ?.libPaths. Also, you may want to tell your sysadm to change HOME to a non-UNC path (which is a bit odd). In the worst case scenario, you can try to map the UNC path to a drive letter and change .libPaths() accordingly, e.g. # Assuming the first lib path is the problematic one: path - .libPaths()[1] # Map to drive letter Z system2(net, args=c(use, Z:, path)) # Update so that packages are installed to that directory .libPaths(Z:/) Then retry to install... If you don't understand the above, talk to your sysadm. /Henrik On Thu, Jan 9, 2014 at 8:46 AM, Ravi Varadhan ravi.varad...@jhu.edu wrote: Hi, I am using following R version: version _ platform i386-w64-mingw32 arch i386 os mingw32 system i386, mingw32 status major 3 minor 0.1 year 2013 month 05 day16 svn rev62743 language R version.string R version 3.0.1 (2013-05-16) nickname Good Sport I was able to build the source of a package without any errors or warnings. However, when I try to install the package, I get the following error messages. Can someone point me to what I am doing wrong? Thanks in advance, Ravi install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, repos=NULL, type=source) Installing package into '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0' (as 'lib' is unspecified) '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. * installing *source* package 'BB' ... ** R ** demo ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices ** building package indices ** installing vignettes ** testing if installed package can be loaded *** arch - i386 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted *** arch - x64 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted ERROR: loading failed for 'i386', 'x64' * removing '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' * restoring previous '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' Warning messages: 1: running command 'C:/PROGRA~1/R/R-30~1.1/bin/i386/R CMD INSTALL -l \\homer.win.ad.jhu.edu\users$\rvaradh1\Documents\R\win-library\3.0 H:/Documents/computations/BB_2014.01-1.tar.gz' had status 1 2: In install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, : installation of package 'H:/Documents/computations/BB_2014.01-1.tar.gz' had non-zero exit status [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem with Rstudio e X11
Unless you have the same issues using plain R, this sounds like a question specific to RStudio which needs to be addressed to https://support.rstudio.com/ Henrik On Jan 15, 2014 6:35 AM, Ronaldo Reis Júnior chryso...@gmail.com wrote: Hi all, I has astrange problem with Rstudio desktop and X11 display. Any plot command in Rstudio give mea error on cairo device. I try reinstall R (from apt-get) and all packages from the source but the problem remains the same. In my notebook (amd64) with the similar debian instalation all work fine, but in my desktop (i386) its dont work. Looking for capabilities in R and Rstudio I get this: In R: capabilities() jpeg png tifftcltk X11 aqua http/ftp sockets libxml TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE fifo cledit iconv NLS profmem cairo TRUE TRUE TRUE TRUE TRUE TRUE In RStudio capabilities() jpeg png tiff tcltk X11 aqua http/ftp sockets libxml TRUE TRUE TRUE TRUEFALSEFALSE TRUE TRUE TRUE fifo clediticonv NLS profmemcairo TRUE TRUE TRUE TRUE TRUE TRUE Anybody have this problem with Rstudio on Linux? My R version: R version 3.0.2 (2013-09-25) -- Frisbee Sailing My Rstudio Version:Version 0.98.490 Where is the problem? Any idea? Any linux package or configuration that I need? Thanks Ronaldo -- 1 Prof. Ronaldo Reis Júnior | .''`. UNIMONTES/DBG/Lab. Ecologia Comportamental e Computacional | : :' : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil | `- Fone: (38) 3229-8192 | ronaldo.r...@unimontes.br | http://www.ppgcb.unimontes.br/lecc | LinuxUser#: 205366 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do you install cran mac binaries
As you install basically all CRAN packages and all OSes; install.packages(forecast) /Henrik On Mon, Jan 27, 2014 at 8:18 PM, ce zadi...@excite.com wrote: Sorry if the question is stupid, how you you install mac os binaries like in : http://cran.r-project.org/bin/macosx/contrib/r-release/forecast_5.0.tgz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do you install cran mac binaries
Whether a package is install from source or from an available binary is controlled by argument 'type', cf. ?install.packages. I believed that, just as on Windows, the default on OSX was to install from binaries, but I might be wrong, or you have changed the settings of the below option. So, instead, try: install.packages(forecast, type=mac.binary.leopard) You can set this as an option once per R session, i.e. options(pkgType=mac.binary.leopard), and then it's enough to do: install.packages(forecast) To make that option permanent across R sessions, see ?.Rprofile. BTW, you want to use both instead of mac.binary.leopard. /Henrik On Tue, Jan 28, 2014 at 3:09 AM, ce zadi...@excite.com wrote: But in crran page it says mac binaries ? if I do install.library, it compiles the package. My old mac can't compile some packages. that's why I need to install binaries directly if possible. -Original Message- From: Henrik Bengtsson [h...@biostat.ucsf.edu] Date: 01/28/2014 12:30 AM To: ce zadi...@excite.com CC: r-help@r-project.org Subject: Re: [R] How do you install cran mac binaries As you install basically all CRAN packages and all OSes; install.packages(forecast) /Henrik On Mon, Jan 27, 2014 at 8:18 PM, ce zadi...@excite.com wrote: Sorry if the question is stupid, how you you install mac os binaries like in : http://cran.r-project.org/bin/macosx/contrib/r-release/forecast_5.0.tgz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.