Re: [R] Fwd: Wanted to learn R Language

2017-11-30 Thread Hadley Wickham
Or try haven::read_xpt(): http://haven.tidyverse.org/reference/read_xpt.html Hadley On Thu, Nov 30, 2017 at 3:13 PM, Jim Lemon wrote: > Hi SAS_learner, > Have a look at the read.xport function in the foreign package. > > Jim > > On Fri, Dec 1, 2017 at 7:50 AM, SAS_learner wrote: >> Hello all ,

Re: [R] Problem installing libxml2 under Homebrew

2018-02-17 Thread Hadley Wickham
Is there a reason that you can't use the binary provided by CRAN? That's the easiest way to get xml2. Hadley On Sat, Feb 17, 2018 at 1:53 AM, Peter Meilstrup wrote: > i am trying to install xml2 from CRAN, and it is throwing an error > that it cannot find the libxml2 library configuration. > > Th

Re: [R] Converting a list to a data frame

2018-05-03 Thread Hadley Wickham
On Wed, May 2, 2018 at 11:53 AM, Jeff Newmiller wrote: > Another approach: > > > library(tidyr) > L <- list( A = data.frame( x=1:2, y=3:4 ) > , B = data.frame( x=5:6, y=7:8 ) > ) > D <- data.frame( Type = names( L ) >, stringsAsFactors = FALSE >

Re: [R] Extract function parameters from a R expression

2018-06-20 Thread Hadley Wickham
You need to recursively walk the parse tree/AST. See, e.g., https://adv-r.hadley.nz/expressions.html#ast-funs Hadley On Wed, Jun 20, 2018 at 10:08 AM, Sigbert Klinke wrote: > Hi, > > I have read an R program with > > expr <- parse("myRprg.R") > > How can I extract the parameters of a specifc R c

Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-21 Thread Hadley Wickham
On Fri, May 19, 2017 at 6:38 AM, S Ellison wrote: >> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be >> either TRUE or FALSE and consequently is NA. >> >> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE. >> >> As I said *think* about it; don't just go with your immedia

Re: [R] Math ops behaviour with multiple classes

2017-06-08 Thread Hadley Wickham
On Thu, Jun 8, 2017 at 2:45 PM, Bert Gunter wrote: > I think you may be confusing (S3) class and ?mode. Your point is well made, but to be precise, I think you should talk about the "type of" an object, not it's mode. mode() is a wrapper around typeof(), designed (I believe) for S compatibility.

Re: [R] Inheritance for S3 classes

2017-08-08 Thread Hadley Wickham
You might find http://adv-r.hadley.nz/s3.html to be helpful (in particular, http://adv-r.hadley.nz/s3.html#constructors-1, gives my advice about subclass constructors) Hadley On Mon, Aug 7, 2017 at 7:06 PM, Kym Nitschke wrote: > Hi R Users, > > I am relatively new to programming in R … so I apol

Re: [R] tidyverse repeating error: "object 'rlang_mut_env_parent' not found"

2017-08-14 Thread Hadley Wickham
The most likely explanation is you have a new version of dplyr/tibble and an old version of rlang. Try re-installing rlang. Hadley On Mon, Aug 14, 2017 at 9:26 AM, Szumiloski, John wrote: > UseRs, > > When doing some data manipulations using the tidyverse, I am repeatedly > getting the same err

Re: [R] functions from 'base' package are not accessible

2017-08-24 Thread Hadley Wickham
This was a change in tidyr 0.7.0 that is causing a lot of confusion, so we are preparing tidyr 0.7.1 which will back this change out. If you want a work around in the meantime, you can express your operation a bit more elegantly as: library(tidyr) df <- data.frame(v1 = 1:5, somestring = 6:10, v3

Re: [R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread Hadley Wickham
I just finished the first draft of the chapters on OO programming for the 2nd edition of "Advanced R": https://adv-r.hadley.nz - you might find them helpful. Hadley On Thu, Sep 14, 2017 at 7:58 AM, Alexander Shenkin wrote: > Hello all, > > I am trying to decide how to structure an R package. Sp

Re: [R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread Hadley Wickham
> Did you read this? > https://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf > > Maybe it could give you some insight in how to create package. That resource is ~9 years old. There are more modern treatments available. You can read mine at http://r-pkgs.had.co.nz. Hadley -- http:/

Re: [R] httr package syntax (PUT)

2016-06-02 Thread Hadley Wickham
On Wed, Jun 1, 2016 at 7:16 PM, Jared Rodecker wrote: > Greetings fellow R users. > > I'm struggling with the syntax of submitting a PUT request > > I'm trying to insert a few PUT requests into some legacy R code that I have > that performs daily ETL on a small database. These requests will add us

Re: [R] About identification of CRAN CHECK machines in logs

2016-06-09 Thread Hadley Wickham
On Thu, Jun 9, 2016 at 9:24 AM, Marcelo Perlin wrote: > Hi, > > I recently released two packages (RndTexExams and GetTDData) in CRAN and > I'm trying to track the number of downloads and location of users. > > I wrote a simple script to download and analyze the log files in http://cran > -logs.rst

Re: [R] About identification of CRAN CHECK machines in logs

2016-06-10 Thread Hadley Wickham
On Fri, Jun 10, 2016 at 8:27 AM, Marcelo Perlin wrote: > I don't know Hadley. But you can see evidence of "something" systematically > installing the packages in the log data. From my two CRAN packages I noticed > a high correlation in the number of downloads. > > Try the following script, which w

Re: [R] Build command in library(devtools)

2016-07-20 Thread Hadley Wickham
The first place to start is to make sure you have the latest version of devtools. If that doesn't work, please file an issue on devtools' GitHub. Hadley On Wednesday, July 20, 2016, Steven Yen wrote: > Here is what I found. I had to go back to as early as R 3.0.3 (March, > 2014) along with Rtoo

Re: [R] Date Time in R

2016-07-26 Thread Hadley Wickham
I'd recommend reading up on how to create a minimal reproducible example (e.g. http://r4ds.had.co.nz/exploratory-data-analysis.html). It is unlikely anyone will be able to help you unless you can reliably communicate _exactly_ what you're doing. Unlike human languages, computer languages are extrem

Re: [R] lm() silently drops NAs

2016-07-26 Thread Hadley Wickham
On Tue, Jul 26, 2016 at 3:24 AM, Martin Maechler wrote: > I have been asked (in private) Martin was very polite to not share my name, but it was me :) > > Hi Martin, > > y <- c(1, 2, 3, NA, 4) > x <- c(1, 2, 2, 1, 1) > > t.test(y ~ x) > lm(y ~ x) > > > Normally, most R fu

Re: [R] lm() silently drops NAs

2016-07-26 Thread Hadley Wickham
> I think that's a bit too strict for me, so I wrote my own: > > na.warn <- function(object, ...) { > missing <- complete.cases(object) > if (any(missing)) { > warning("Dropping ", sum(missing), " rows with missing values", > call. = FALSE) > } > > na.exclude(object, ...) > } That shou

Re: [R] read.xlsx function crashing R Studio

2016-08-22 Thread Hadley Wickham
Or readxl. Hadley On Mon, Aug 22, 2016 at 5:54 AM, jim holtman wrote: > try the openxlsx package > > > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > Tell me what you want to do, not how you want to do it. > > On Sun, Aug 21, 2016 at 1:30 PM, Kevin Kowitsk

Re: [R] workflow getting UTF-8 csv in and out of R on Mac (spreadsheet editor)

2016-09-02 Thread Hadley Wickham
You can use readr::write_excel_csv() which adds a BOM that forces excel to read as UTF-8. Hadley On Friday, September 2, 2016, Erich Neuwirth wrote: > read_excel in Hadley’s readxl package > should handle your encoding problems. > Writing Excel files on a Mac, however, still is somewhat messy.

Re: [R] library(xlsx) fails with an error: Error: package ‘rJava’ could not be loaded

2015-04-20 Thread Hadley Wickham
You might want to try readxl instead, as it doesn't have any external dependencies. Hadley On Sat, Apr 18, 2015 at 3:07 PM, John Sorkin wrote: > Windows 7 64-bit > R 3.1.3 > RStudio 0.98.1103 > > > I am having difficulty loading and installing the xlsx package. The > loading occurred without any

Re: [R] misbehavior with extract_numeric() from tidyr

2015-04-20 Thread Hadley Wickham
On Mon, Apr 20, 2015 at 1:57 PM, arnaud gaboury wrote: > On Mon, Apr 20, 2015 at 6:09 PM, William Dunlap wrote: > >> The hyphen without a following digit confuses tidyr::extract_numeric(). >> E.g., >>> extract_numeric("23 ft-lbs") >>Warning message: >>In extract_numeric("23 ft-lbs") :

Re: [R] Rtools 3.3 is not compatible with R 3.2.0.?

2015-04-21 Thread Hadley Wickham
It's been fixed in the dev version, and I'm planning on submitting to CRAN in the near future. Hadley On Tue, Apr 21, 2015 at 6:01 PM, Shi, Tao wrote: > hi list, > > Any updates on this issue? Thank you very much! > > Tao > > >> devtools::install_github("rstudio/packrat") > WARNING: Rtools 3.3 f

Re: [R] Problem with particular file in XML package?

2015-05-28 Thread Hadley Wickham
I have also seen this problem on a student's windows machine (with R 3.2.0 and on multiple mirrors). It appeared that the package zip itself was being corrupted (with an error to the tune of downloaded file size does not agree with actual file size). The most likely explanation that I could come up

Re: [R] dplyr - counting a number of specific values in each column - for all columns at once

2015-06-16 Thread Hadley Wickham
On Tue, Jun 16, 2015 at 12:24 PM, Dimitri Liakhovitski wrote: > Hello! > > I have a data frame: > > md <- data.frame(a = c(3,5,4,5,3,5), b = c(5,5,5,4,4,1), c = c(1,3,4,3,5,5), > device = c(1,1,2,2,3,3)) > myvars = c("a", "b", "c") > md[2,3] <- NA > md[4,1] <- NA > md > > I want to count num

Re: [R] what constitutes a 'complete sentence'?

2015-07-03 Thread Hadley Wickham
It might be a line break problem - I think you want: Description: Functions designed to test for single gene/phenotype association and for pleiotropy on genetic and genomic data. Hadley On Fri, Jul 3, 2015 at 10:09 AM, Federico Calboli wrote: > Hi All, > > I am upgrading a package for CRAN,

Re: [R] what constitutes a 'complete sentence'?

2015-07-03 Thread Hadley Wickham
In that case, you need to create a minimal reproducible example and make it publicly available. Hadley On Friday, July 3, 2015, Federico Calboli wrote: > > > On 3 Jul 2015, at 12:14, Hadley Wickham > wrote: > > > > It might be a line break problem - I think you w

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread Hadley Wickham
It doesn’t appear to me that mpfr was ever designed to handle expressions as the first argument. >>> >>> This could be a start. Obviously one would wnat to include code to do other >>> substitutions probably using the all.vars function to pull out the other >>> “constants” and ’numeric

Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Hadley Wickham
Have you tried explicitly print()ing the lattice graphics in your knitr doc? Hadley On Friday, July 10, 2015, Rich Shepard wrote: > Hadley's ggplot2 book is quite old and a new version is in the works, but > not yet out. I've been using lattice graphics but the knitr package doesn't > support

Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Hadley Wickham
You shouldn't be explicitly opening a device in a knitr document. I think maybe you should post a minimal document so we can figure out what's going wrong. Hadley On Friday, July 10, 2015, Rich Shepard wrote: > On Fri, 10 Jul 2015, Hadley Wickham wrote: > > Have you tri

Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Hadley Wickham
epard wrote: > On Fri, 10 Jul 2015, Hadley Wickham wrote: > >> You shouldn't be explicitly opening a device in a knitr document. > > > Hadley, > > Didn't think so. > >> I think maybe you should post a minimal document so we can figure out >> what

Re: [R] For Hadley Wickham: Need for a small fix in haven::read_spss

2015-07-20 Thread Hadley Wickham
(FWIW this would've been better send to me directly or filed on github, rather than sent to R-help) I think this is more of a problem with the way that you're accessing the info, than the design of the underlying structure. I'd do something like this: attr_default <- function(x, which, default) {

Re: [R] ggplot2 - Specifying Colors Manually

2015-07-22 Thread Hadley Wickham
Try this: ggplot(mydf,aes(x)) + geom_line(aes(y = y1, colour = "y1")) + geom_line(aes(y = y2, colour = "y2")) + scale_color_manual(values = c(y1 = "green4", y2 = "blue2")) Note that you don't need to use `mydf` and names in the manual scale should match the values in the aes() calls. Alsoi

Re: [R] ggplot2 - geom_text() with date as x-axis

2015-07-30 Thread Hadley Wickham
I'm a bit confused what you're trying to accomplish - the mix of annotate() and geom_text() is confusing. The following code works for me, and I think might be what you want: ggplot(ins, aes(td, glucose)) + geom_point(colour = "red") + geom_line(colour = "blue") + annotate("text", x = texdat

Re: [R] dplyr and function length()

2015-08-04 Thread Hadley Wickham
> No, the effect I described has nothing to do wit USING dplyr. It occurs with > any (preexisting) data.frame once dplyr is LOADED (require(dplyr). It is > this silent, sort of "backward acting" effect that disturbs me. You're going to need to provide some evidence for that charge: dplyr does not

Re: [R] dplyr and function length()

2015-08-04 Thread Hadley Wickham
>> length(df[,1]). >> >> Both commands will return n. >> >> However, once dplyr is loaded, >> >> length(df[,1]) will return a value of 1. >> >> length(df$m1) and also length(df[[1]]) will correctly return n. >> >> I know that using length() may not be the most elegant or efficient way to >> get th

Re: [R] attributes in dplyr and haven

2015-08-04 Thread Hadley Wickham
Install the latest version of dplyr? Should be fixed there. Hadley On Tue, Aug 4, 2015 at 9:40 AM, Conklin, Mike (GfK) wrote: > I read in spss files using haven's read_spss. Each column then gets > attributes assigned named > label - a long description of the variable > class -" labelled" > labe

Re: [R] writing binary data from RCurl and postForm

2015-08-05 Thread Hadley Wickham
> I think that is because the value returned from postForm has an attribute; > remove it by casting the return to a vector > > fl <- tempfile(fileext=".pdf") > writeBin(as.vector(postForm(url, binary=TRUE)), fl) > > > The httr package might also be a good bet > > writeBin(content(POST(url)),

Re: [R] Memory hungry routines

2014-12-29 Thread Hadley Wickham
You might find the advice at http://adv-r.had.co.nz/memory.html helpful. Hadley On Tue, Dec 30, 2014 at 7:52 AM, ALBERTO VIEIRA FERREIRA MONTEIRO wrote: > Is there any way to detect which calls are consuming memory? > > I run a program whose global variables take up about 50 Megabytes of > memory

Re: [R] R vs. RStudio?

2015-01-12 Thread Hadley Wickham
On Mon, Jan 12, 2015 at 2:01 AM, peter dalgaard wrote: > >> On 11 Jan 2015, at 11:30 , Duncan Murdoch wrote: >> >> >> - I don't like the tiled display. I find it doesn't give me enough space. >> > > This is a mixed blessing. For teaching purposes, it helps avoid shuffling > windows to uncover t

Re: [R] R vs. RStudio?

2015-01-12 Thread Hadley Wickham
Is there a reason you don't just click the zoom button? Hadley On Mon, Jan 12, 2015 at 8:22 AM, John Fox wrote: > Dear Peter and Jeff, > > I've used RStudio in teaching for quite some time now. For displaying > graphics, I open a windows() graphics device on a Windows PC or a quartz() > device on

Re: [R] stringr::str_split_fixed query

2015-01-15 Thread Hadley Wickham
FWIW this is fixed in the dev version of stringr which uses stringi under the hood: > stringr::str_split_fixed('ab','',2) [,1] [,2] [1,] "a" "b" > stringr::str_split_fixed('ab','',3) [,1] [,2] [,3] [1,] "a" "b" "" Hadley On Wed, Jan 14, 2015 at 12:47 PM, David Barron wrote: > I'm p

Re: [R] Latest version of Rtools is incompatible with latest version of R !!

2015-01-16 Thread Hadley Wickham
>> Funnily, this problem disappears when I use RTools31.exe. And, I am not the >> only one facing this issue. A lot of people in my group (in which we all are >> learning R) are facing the same problem. I am really puzzled as to why >> RTools32.exe isn't compatible with R 3.1.2 !! >> Thanks agai

Re: [R] Passing a Data Frame Name as a Variable in a Function

2015-01-29 Thread Hadley Wickham
On Thu, Jan 29, 2015 at 11:43 AM, Alan Yong wrote: > Much thanks to everyone for their recommendations! I agree that fishing in > the global environment isn't ideal & only shows my budding understanding of R. > > For now, I will adapt Chel Hee's "length(eval(parse(text=DFName))[,1])" > solution

Re: [R] Package build help

2015-02-11 Thread Hadley Wickham
On Sun, Feb 8, 2015 at 5:15 PM, Duncan Murdoch wrote: > On 08/02/2015 4:06 PM, Glenn Schultz wrote: >> Hello All, >> >> I am in the final stages of building my first package "BondLab" and the >> check throughs the following warning. I think this is namespace thing. I >> have not done anything

Re: [R] Shiny User Group

2015-02-12 Thread Hadley Wickham
Maybe https://groups.google.com/forum/#!forum/shiny-discuss ? Hadley On Thu, Feb 12, 2015 at 9:07 AM, Doran, Harold wrote: > I found a google user group for shiny, and am curious if there is an SIG as > well. Didn't see one in my searches, but looking for an active place to ask > questions and

Re: [R] %>%

2015-02-17 Thread Hadley Wickham
On Tue, Feb 17, 2015 at 6:02 PM, Hervé Pagès wrote: > On 02/17/2015 02:10 PM, Erich Neuwirth wrote: >> >> AFAIK dplyr imports magrtittr. >> So dplyr ses %>% from migrittr, it does not have its own version. > > But it has its own man page so who knows? If you import and re-export a function from a

Re: [R] dplyr: producing a good old data frame

2015-02-25 Thread Hadley Wickham
Hi John, Just printing the result gives a good indication where the problem lies: > frm %>% rowwise() %>% do(MM=max(as.numeric(.))) Source: local data frame [6 x 1] Groups: MM 1 2 3 4 5 6 do() is designed to produce scalars (e.g. a linear model), not vectors, so it doesn't join t

Re: [R] readHTMLTable() in XML package

2015-03-02 Thread Hadley Wickham
This somewhat simpler rvest code does the trick for me: library(rvest) library(dplyr) i <- 1:10 urls <- paste0('http://games.crossfit.com/scores/leaderboard.php?stage=5', '&sort=0&division=1®ion=0&numberperpage=100&competition=0&frontpage=0', '&expanded=1&year=15&full=1&showtoggles=0&hidedrop

Re: [R] Using and abusing %>% (was Re: Why can't I access this type?)

2015-03-27 Thread Hadley Wickham
> I didn't dispute whether '%>%' may be useful -- I just pointed out that it > is slow. However, it is only part of the problem: 'filter()' and > 'select()', although aesthetically pleasing, also seem to be slow: > >> all.states <- data.frame(state.x77, Name = rownames(state.x77)) >> >> f1 <- func

Re: [R] idiom for constructing data frame

2015-04-03 Thread Hadley Wickham
On Tue, Mar 31, 2015 at 6:42 PM, Sarah Goslee wrote: > On Tue, Mar 31, 2015 at 6:35 PM, Richard M. Heiberger wrote: >> I got rid of the extra column. >> >> data.frame(r=seq(8), foo=NA, bar=NA, row.names="r") > > Brilliant! > > After much fussing, including a disturbing detour into nested lapply >

Re: [R] open xlsx file using read.xls function of gdata package

2015-04-03 Thread Hadley Wickham
You might try the readxl package - it's only available on github but it reads both xlsx and xls. All going well, it should be on its way to CRAN next week. Hadley On Friday, April 3, 2015, Luigi Marongiu wrote: > Dear all, > I am trying to open excel files using the gdata package. I can do that

Re: [R] RMarkdown vignettes v. Jupyter notebooks?

2018-10-11 Thread Hadley Wickham
I'd highly recommend Yihui's extensive write up: https://yihui.name/en/2018/09/notebook-war/ Hadley On Thu, Oct 11, 2018 at 4:08 AM Spencer Graves wrote: > > Hello: > > >What are the differences between Jupyter notebooks and RMarkdown > vignettes? > > >I'm trying to do real time m

Re: [R] Unable to install ggplot2

2019-03-06 Thread Hadley Wickham
rlang works with R 3.1 and up, but it does require compilation from source, which I suspect is the root cause of this problem. Hadley On Wed, Mar 6, 2019 at 5:36 PM peter dalgaard wrote: > > Also, R seems to be version 3.2.x i.e. 3-4 years old. Earliest rlang is anno > 2017 as far as I can tell

Re: [R] Why I can not get work the "tidyverse" and "corrr" libraries

2019-04-17 Thread Hadley Wickham
On Wed, Apr 17, 2019 at 1:06 PM Jeff Newmiller wrote: > > From reading > > > namespace ‘rlang’ 0.3.0 is already loaded, but >= 0.3.1 is required > > it would seem that you need to upgrade your rlang package... Typically this indicates you need to restart R. Hadley -- http://hadley.nz

Re: [R] ATTN: Urgent Guidance Needed on scraping tweets for last 10 years using TwitteR / search twitter function.

2014-07-30 Thread Hadley Wickham
The first twitter message was sent on March 21st, 2006... Hadley On Wed, Jul 30, 2014 at 3:58 AM, Abhishek Dutta wrote: > Hi > > > This is Abhishek and I am trying to look for tweets on 'Election' from > 2000 to YTD. I have registered on twitter and performed a handshake > between the systems as

Re: [R] Just stumbled across this: Advanced R programming text & code - from Hadley

2014-08-11 Thread Hadley Wickham
Or just go to http://adv-r.had.co.nz/ ... Hadley On Sun, Aug 10, 2014 at 9:34 PM, John McKown wrote: > Well, it says that it's from Hadley Wickham. > > https://github.com/hadley/adv-r > > > This is code and text behind the Advanced R programming book. > > The site

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

2014-08-23 Thread Hadley Wickham
In the future, you can avoid this problem by using saveRDS and readRDS. Hadley On Mon, Aug 18, 2014 at 7:30 PM, Jinsong Zhao wrote: > Hi there, > > I have several saved data files (e.g., A.RData, B.RData and C.RData). In > each file, there are some objects with same names but different contents.

Re: [R] URLdecode problems

2014-09-01 Thread Hadley Wickham
Hi Oliver, I think you're being misled by the default behaviour of warnings: they all get displayed at once, before control returns to the console. If you making them immediate, you get a slightly more informative error: > URLdecode("0;%20@%gIL") Warning in URLdecode("0;%20@%gIL") : out-of-ran

Re: [R] Detect expired RSQLiteConnection?

2014-09-02 Thread Hadley Wickham
DBI 0.3 (just released to CRAN) includes a new generic, dbIsValid(), for exactly this purpose. Unfortunately no packages implement a method for it yet, but eventually it will be the right way to detect this problem. (I'm now the maintainer for RSQLite, so I added this to my to do list: https://git

Re: [R] Operator proposal: %between%

2014-09-05 Thread Hadley Wickham
> Please add it if you think it fits, and expand it as discussed, I am not > creating a package for one single utility function. Why not? There's nothing wrong with a package that only provides one function. Hadley -- http://had.co.nz/ __ R-help@r-p

Re: [R] R's memory limitation and Hadoop

2014-09-16 Thread Hadley Wickham
Hundreds of thousands of records usually fit into memory fine. Hadley On Tue, Sep 16, 2014 at 12:40 PM, Barry King wrote: > Is there a way to get around R’s memory-bound limitation by interfacing > with a Hadoop database or should I look at products like SAS or JMP to work > with data that has h

Re: [R] Hadley's book: paper/PDF/etc. versus github

2014-10-03 Thread Hadley Wickham
> Hi, folks. I've got a sort of coupon that would allow me to get a > copy of "Advanced R" by Hadley Wickham at no cost. OTOH, I've already > cloned the github repository, and having the "live" Rmd files (or in > this case, rmd files) is enormously m

Re: [R] Hadley's book: paper/PDF/etc. versus github

2014-10-06 Thread Hadley Wickham
ed, but all the example code was missing (which defeats the > convenience of having it on an ebook reader), I did not check if > everything else was there or not. > > thanks, > > On Fri, Oct 3, 2014 at 6:37 AM, Hadley Wickham wrote: >>> Hi, folks. I've got a sort

Re: [R] How can I overwrite a method in R?

2014-10-09 Thread Hadley Wickham
This is usually ill-advised, but I think it's the right solution for your problem: assignInNamespace("plot.histogram", function(...) plot(1:10), "graphics") hist(1:10) Haley On Thu, Oct 9, 2014 at 1:14 AM, Tim Hesterberg wrote: > How can I create an improved version of a method in R, and have i

Re: [R] "source" command inside R package scripts

2014-10-21 Thread Hadley Wickham
Your source function will be called when the package is _built_, not when it's loaded/attached. There's almost certainly a better way to solve your problem than using source() inside a package Hadley On Tue, Oct 21, 2014 at 6:24 AM, Enrico Bibbona wrote: > I have built a new package. I would lik

Re: [R] How to speed up list access in R?

2014-10-30 Thread Hadley Wickham
Or do all the subsetting in one pass - [ will use a hashmap. Hadley On Thu, Oct 30, 2014 at 12:05 PM, William Dunlap wrote: > You can try using an environment instead of a list. > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > > On Thu, Oct 30, 2014 at 10:02 AM, Thomas Nyberg wrote: >>

Re: [R] Knitr: how to find out from within a .Rmd file the output type?

2014-10-31 Thread Hadley Wickham
Try knitr::opts_knit$get('rmarkdown.pandoc.to') Hadley On Fri, Oct 31, 2014 at 6:56 AM, Michal Kvasnička wrote: > Hi. > > Is there a way how to find out from within a .Rmd file what output format > is generated? > > The reason is this: I write a paper in R markdown in RStudio. Sometimes I > gene

Re: [R] CMD check error

2014-11-18 Thread Hadley Wickham
Do you have a .Rbuildignore? If so, what's in it? Hadley On Tue, Nov 18, 2014 at 7:07 AM, Therneau, Terry M., Ph.D. wrote: > I have a new package (local use only). R CMD check fails with a messge I > haven't seen before, and I haven't been able to guess the cause. > There are two vignettes, bot

Re: [R] Implements XPath 2.0 in R

2014-11-18 Thread Hadley Wickham
Why do you need from xpath 2.0? It will almost certainly be easier to implement similar functionality using a little R code than adding xpath 2.0 support. Hadley On Mon, Nov 17, 2014 at 6:03 AM, Rees Morrison wrote: > Many users of R would like the enhanced extraction capabilities of XPath > 2.

Re: [R] dplyr/summarize does not create a true data frame

2014-11-23 Thread Hadley Wickham
This bug is fixed in the dev version. Hadley On Sunday, November 23, 2014, John Posner wrote: > Thanks to John Kane for an off-list consultation. As the following > annotated transcript shows, it's the group_by() function that transforms a > data frame into something else: a "grouped_df" object

Re: [R] function to avoid <<-

2014-12-02 Thread Hadley Wickham
At the top level do: myenv <- new.env(parent = emptyenv()) Then in your functions do myenv$x <- 50 myenv$x etc You also should not be using data() in that way. Perhaps you want R/sysdata.rda. See http://r-pkgs.had.co.nz/data.html for more details. Hadley On Tue, Dec 2, 2014 at 2:28 AM, Karim

Re: [R] How are packages installed with install_github() updated in RStudio?

2015-08-18 Thread Hadley Wickham
RStudio just calls the same underlying R functions, so it doesn't make any difference that you're using RStudio. Currently, there's no automatic way to update packages installed from github. Hadley On Tue, Aug 18, 2015 at 8:14 AM, John Kane wrote: > Hi Michal, > > Because RStudio seems to use i

Re: [R] Issues with RPostgres

2015-08-27 Thread Hadley Wickham
On Thu, Aug 27, 2015 at 3:46 PM, John McKown wrote: > On Thu, Aug 27, 2015 at 2:29 PM, Abraham Mathew > wrote: > >> I have a user-defined function that I'm using alongside a postgresql >> connection to >> summarize some data. I've connected to the local machine with no problem. >> However, >> the

Re: [R] ggplot2 scale_shape_manual with large numbers instead of shapes

2015-08-27 Thread Hadley Wickham
Something like this? df <- data.frame( x = runif(30), y = runif(30), z = factor(1:30) ) ggplot(df, aes(x, y)) + geom_point(aes(shape = z), size = 5) + scale_shape_manual(values = c(letters, 0:9)) Hadley On Thu, Aug 27, 2015 at 4:48 PM, Marian Talbert wrote: > I'm trying to produce a

Re: [R] Unexpected/undocumented behavior of 'within': dropping variable names that start with '.'

2015-09-20 Thread Hadley Wickham
The problem is that within.data.frame calls as.list.environment with the default value of all.names = FALSE. I doubt this is a deliberate feature, and is more likely to be a minor oversight. Hadley On Sun, Sep 20, 2015 at 11:49 AM, Brian wrote: > Dear List, > > Somewhere I missed something, and

Re: [R] retaining characters in a csv file

2015-09-22 Thread Hadley Wickham
The problem is that quotes in csv files are commonly held to me meaningless (i.e. they don't automatically force components to be strings). Earlier this morning I committed a fix to readr so that numbers starting with a sequence of zeros are read as character strings. You may want to try out the d

Re: [R] Control of x-axis variable ordering in ggplot

2015-10-23 Thread Hadley Wickham
You have two problems: * geom_line() always draws from right-to-left * you're defining colour outside of the plot in a very non-ggplot2 way. Here's how I'd do it: library(ggplot2) data <- data.frame( x = rep(1:4, each = 25), y = rep(1:25, times = 4), g = rep(1:4, each = 25) ) data$x <- dat

Re: [R] Achieve independent fine user control of ggplot geom settings when using groups in multiple geom's

2015-10-30 Thread Hadley Wickham
I'd recommend reading the ggplot2 book - learning more about how scales work in ggplot2 will help you understand why this isn't possible. Hadley On Thu, Oct 29, 2015 at 6:31 PM, sbihorel wrote: > Thank for your reply, > > I may accept your point about the mapping consistency when the different >

[R] R Consortium projects

2015-11-04 Thread Hadley Wickham
ostly focussed on funding people who have the skills to solve a problem. In the future, we will explore how to match up people with skills and people with problems. * Proposals are due Jan 10. Please let me know if you have any questions! Hadley Wickham Chair, ISC -- http://had.

Re: [R] Weird behaviour function args in ellipses

2015-12-11 Thread Hadley Wickham
On Fri, Dec 11, 2015 at 1:13 PM, Duncan Murdoch wrote: > On 11/12/2015 1:52 PM, Mario José Marques-Azevedo wrote: >> >> Hi Duncan and David, >> >> Thank you for explanation. I'm really disappointed with this R "resource". >> I think that partial match, mainly in function args, must be optional and

Re: [R] stopifnot with logical(0)

2015-12-12 Thread Hadley Wickham
On Sat, Dec 12, 2015 at 3:54 AM, Martin Maechler wrote: >> Henrik Bengtsson >> on Fri, 11 Dec 2015 08:20:55 -0800 writes: > > > On Fri, Dec 11, 2015 at 8:10 AM, David Winsemius > wrote: > >> > >>> On Dec 11, 2015, at 5:38 AM, Dario Beraldi > wrote: > >>> > >>>

Re: [R] stopifnot with logical(0)

2015-12-14 Thread Hadley Wickham
On Sat, Dec 12, 2015 at 1:51 PM, Martin Maechler wrote: >>>>>> Hadley Wickham >>>>>> on Sat, 12 Dec 2015 08:08:54 -0600 writes: > > > On Sat, Dec 12, 2015 at 3:54 AM, Martin Maechler > > wrote: > >>>>>>>

Re: [R] stopifnot with logical(0)

2015-12-14 Thread Hadley Wickham
>> I wonder if R is missing an equality operator for this case. Currently: >> >> * == is suboptimal because it's vectorised >> * all.equal is suboptimal because it returns TRUE or a text string >> * identical is suboptimal because it doesn't do common coercions >> >> Do we need another function (eq

Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-16 Thread Hadley Wickham
On Tue, Dec 15, 2015 at 9:55 AM, Martin Maechler wrote: > > >[] > > > You are missing the closing bracket on the boxplot() > > command. Just finish with a ')' > > Hmm... I once learned > > '()' =: parenthesis/es > '[]' =: bracket(s) > '{}' =: brace(s) > > Of course, I'm

Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-16 Thread Hadley Wickham
On Wed, Dec 16, 2015 at 9:34 AM, Hadley Wickham wrote: > On Tue, Dec 15, 2015 at 9:55 AM, Martin Maechler > wrote: >> >> >>[] >> >> > You are missing the closing bracket on the boxplot() >> > command. Ju

Re: [R] vjust unresponsive (ggplot2)

2015-12-23 Thread Hadley Wickham
vjust was always a hack that I never thought should work. The margins parameter is the correct way to solve this problem as of ggplot2 2.0.0. Hadley On Tuesday, December 22, 2015, Nordlund, Dan (DSHS/RDA) wrote: > Ista, > > You are correct, I was not at the latest release of ggplot2. I updated

Re: [R] Updating github R packages

2016-02-17 Thread Hadley Wickham
It will be included in the next version of devtools - it's totally do-able, but no one has done it yet. Hadley On Wed, Feb 17, 2016 at 6:44 PM, Jeff Newmiller wrote: > AFAIK the answer is no. That would be one of the main drawbacks of depending > on github for packages. It isn't really a packag

Re: [R] simple question on data frames assignment

2016-04-07 Thread Hadley Wickham
== is also vectorised, and you're better off with TRUE and FALSE rather than 1 and 0, so I'd recommend: colordata$response <- colordata$color == 'blue' Hadley On Thu, Apr 7, 2016 at 6:52 AM, David Barron wrote: > ifelse is vectorised, so just use that without the loop. > > colordata$response <-

Re: [R] installation of dplyr

2016-04-19 Thread Hadley Wickham
You normally see these errors when compiling on a vm that has very little memory. Hadley On Tue, Apr 19, 2016 at 2:47 PM, Ben Tupper wrote: > Hello, > > I am getting a fresh CentOS 6.7 machine set up with all of the goodies for R > 3.2.3, including dplyr package. I am unable to successfully inst

Re: [R] with vs. attach

2016-05-06 Thread Hadley Wickham
You may want to read http://rpubs.com/hadley/157957, which captures my latest thinking (and tooling) around this problem. Feedback is much appreciated. Hadley On Fri, May 6, 2016 at 2:14 PM, David Winsemius wrote: > >> On May 6, 2016, at 5:47 AM, Spencer Graves >> wrote: >> >> >> >> On 5/6/201

Re: [R] with vs. attach

2016-05-09 Thread Hadley Wickham
On Sun, May 8, 2016 at 7:28 PM, Bert Gunter wrote: > Jeff: > > That's easy to do already with substitute(), since you can pass around > an unevaluated expression (a parse tree) however you like. As I read > it, (admittedly quickly) what it's main feature is that it allows you > more control over t

Re: [R] with vs. attach

2016-05-09 Thread Hadley Wickham
On Mon, May 9, 2016 at 7:12 AM, peter dalgaard wrote: > > On 09 May 2016, at 02:46 , Bert Gunter wrote: > >> ... To be clear, Hadley or anyone else should also feel free to set me >> straight, preferably publicly, but privately if you prefer. > > Not really to "set anyone straight", but there are

Re: [R] Question about ‘The R Project’.

2016-11-14 Thread Hadley Wickham
>> We have a question about ‘The R Project’. >> >> It looks like it’s an open source software, but the document from the >> website shows that it’s free of use not free of price. >> >> Please, confirm us the if it cost fees to use it for commercial use. >> >> If needed, could you inform us the pri

Re: [R] on ``unfolding'' a json into data frame columns

2016-11-29 Thread Hadley Wickham
Two quick hints: * use simplifyDataFrame = FALSE in fromJSON() * read https://jennybc.github.io/purrr-tutorial/ls02_map-extraction-advanced.html (and https://jennybc.github.io/purrr-tutorial/) Hadley On Tue, Nov 29, 2016 at 8:06 AM, Daniel Bastos wrote: > Greetings! > > In an SQL table, I hav

Re: [R] Unexpected interference between dplyr and plm

2016-11-29 Thread Hadley Wickham
On Tue, Nov 29, 2016 at 11:52 AM, William Dunlap wrote: >>The other option would be to load dplyr first (which would give the waring >> that >stats::lag was masked) and then later load plm (which should give a >> further >warning that dplyr::lag is masked). Then the plm::lag function will >> be fo

Re: [R] ggplot aestetics: beginner question - I am lost in endless possibilites

2016-12-15 Thread Hadley Wickham
You are going to find your life much easier if you: * Organise your code so it's easier to read * Use a consistent naming scheme for your variables * Learn a bit more about how to modify variables succintly Here's my rewriting of your script to make it easier to see what's going on. library(tidy

Re: [R] Assessing the name of an object within an argument

2017-01-10 Thread Hadley Wickham
You might find http://adv-r.had.co.nz/Computing-on-the-language.html helpful. Hadley On Tue, Jan 10, 2017 at 2:49 AM, wrote: > Hi All, > > I have a function like > > my_func <- function(dataset) > { > some operation > } > > Now I would like not only to operate on the dataset (how this is done

Re: [R] Failure to understand namespaces in XML::getNodeSet

2017-01-31 Thread Hadley Wickham
See the last example in ?xml2::xml_find_all or use xml2::xml2::xml_ns_strip() Hadley On Tue, Jan 31, 2017 at 9:43 AM, Mark Sharp wrote: > I am trying to read a series of XML files that use a namespace and I have > failed, thus far, to discover the proper syntax. I have a reproducible > example

Re: [R] Failure to understand namespaces in XML::getNodeSet

2017-01-31 Thread Hadley Wickham
E), "/WorkSet//Description") > > ## Produces the following error message. > Error in UseMethod("xml_find_all") : > no applicable method for 'xml_find_all' applied to an object of class > "character" > > > > R. Mark Sharp, Ph.D.

  1   2   3   4   5   6   7   8   9   10   >