Tidyverse Tutorial

Last week, I gave an overview of bunch of tidyverse packages (tibble, dplyr, tidyr, ggplot, readr, purrr) to the Davis R-Users’ Group. Here is that talk (and since videos don’t display everywhere this blog is syndicated, here is the YouTube link).

I mention early in the talk that the github_markdown specification in the YAML header produces a conveniently GitHub-renderable markdown file – here that is if you’d like to follow along, or you can download the rendered R Notebook (nb.html) file, which itself includes the R Markdown file (Awesome! In the upper right of the html file, click “Code” -> “Download Rmd”).

One final note, on the speed of tidyverse functions. Some tidyverse functions really do offer a speed advantage over base R (e.g. read_csv and filter), but the map speed advantage I mention here over lapply seems to be an artifact of both being wrapped in a map2 call in a data_frame call. They are actually equally fast. In my mind, the benefit of the tidyverse is that it makes R easier to write and read, which makes it less bug-prone and more approachable for beginners. It does that without imposing a speed penalty, and in some cases provides a little acceleration as a bonus.

Diversity of both grazers and habitats is key for healthy ecosystems


Me working on the vertical rock wall that was the stage for this experiment. Behind me is a rock bench covered with living organisms and a retreating Pacific Ocean.

In order to maintain healthy ecosystems, we need to consider how environments change in relation to the organisms living in those environments. My colleagues and I recently published a paper showing how the varieties of both habitats and animals interact to speed the recovery of seaweeds on a rocky shore. Habitat and animal diversity were important on their own, but having a range of habitats was essential to promoting recovery of seaweeds when an important grazing animal species was removed from the community. Thus, a mix of habitats for organisms to utilize may provide a buffer against the loss of species. Maybe variety really is the spice of life.

Understanding the causes and consequences of biodiversity is a major motivation for ecologists, and these causes and effects may be related in important ways. The aspects of an environment that allow diverse communities to develop may also help explain how biodiversity influences essential processes in ecosystems, such as the ability of communities to recover after being disturbed. In our study, recovery meant that seaweeds grew back quickly after we removed them from small areas.

The stage for our study was a vertical rock wall high up in the intertidal zone at Bodega Marine Reserve. This location features a wide variety of life in very small areas, and much of this life is slow-moving or does not move at all. These aspects, along with steep environmental gradients where land becomes sea, have made rocky shores ideal systems for conducting experiments in the rough and tumble of nature for many decades.

Our cast of characters included stalwart barnacles, several varieties of snails (periwinkles and limpets), and a mélange of green and red seaweeds. These creatures interact with one another in a number of ways: seaweeds and barnacles compete for space on rocks, snails eat seaweeds, barnacles protect small seaweeds from being eaten by snails (they can’t reach between the barnacles), limpets can bulldoze young barnacles from rocks, and tiny periwinkles live inside dead barnacle shells. Given all of these interactions, it can be difficult to predict what will happen when we change something in the system, but this is exactly what excites me about ecology.

Here’s how we designed our experiment: we manipulated the cover of barnacles and the number of species of snails after removing seaweeds from small areas on the shore, and we tracked the recovery of seaweeds over the course of one year. We first set up areas in which we 1) left barnacles completely intact, 2) removed all barnacles, or 3) removed barnacles from only one half of the area. This last “half barnacle” treatment we considered to be more diverse because it contained two distinct habitat types. For every habitat type we then manipulated the number of snail species that were present: an intact snail community with periwinkles and two types of limpets, and three communities each with only one type of these snails (we removed the other snail types).


The figure (above) summarizes the results for the seaweeds that grow slowly and tend to stay on the shore for long periods of time, so-called “perennial” seaweeds. The panel on the left shows the final percent cover of perennial seaweed in each barnacle and herbivore treatment, while the panel on the right shows cover of perennial seaweeds on each side of the areas in the half barnacle treatment. When the ribbed limpet was present, seaweeds recovered fastest in areas completely covered with barnacles likely because barnacles provided predation refuge from the ribbed limpet, which is the largest of the snails and a habitat generalist. However, when the ribbed limpet was removed (the rough limpet and periwinkle treatments) seaweeds recovered fastest in areas in which both barnacles and bare rock habitats were present. This happened because of the characteristics of the other snails that were present. The rough limpet tends to avoid barnacle areas (its shell actually grows to fit the shape of the rock surface!) so seaweeds were able to recover on the side with barnacles where it did not graze (see photograph). Tiny periwinkles, on the other hand, hang out near barnacles, but seaweeds recover faster there, too, because the barnacle-free side became covered with weedy seaweeds that choke out the perennials.


One of the plots from our experiment. The top half has no barnacles and features several visible rough limpets, but the bottom half in full of barnacles and tiny periwinkles. Recovery of perennial seaweed was faster on the side of plots with barnacles.

The results of our experiment were complex and not easy to predict ahead of time based on our natural history knowledge, even though we worked in a relatively small and simple ecosystem. For me, this is much like changing your look when you only have a few articles of clothing at your disposal. A typical suit can look very different if you add a cowboy hat or a bolo tie. What if you threw some spandex into the mix? Chaos?

[NOTE: Originally published in The Aggie Brickyard in 2016]

Beyond Forest Fires: Bringing Chaparral Fire Stories to Light


It’s Friday evening, late July, and we’re driving south down I-5  Universal Studios and the new Wizarding World of Harry Potter. Jim Dale’s rendition of the sixth Harry Potter book plays from the car speakers. Then, up ahead—a bright orange glow in the dark hills ahead. These are the flames of the Sand Fire, which would burn just over 40,000 acres near Santa Clarita, California in the next several days. The next day, ash was falling on the rooftops of recreated Hogsmeade shops and the sky was a smoky pink. The California wildfire season was heating up.


Smoke from  the Sand Fire from Universal Studios–Hollywood. (Photo: A. Weill)

California’s 2016 fire season had begun long before that July evening—indeed, some argue that “fire seasons” have gotten so long that such a thing doesn’t really exist anymore—but late July is still a time for big fires to really get going. The Sand Fire wasn’t the only big fire to start then. That same exact day—July 22, 2016—another fire was reported in Big Sur, California. That one was the Soberanes Fire, California’s biggest fire of the year so far, and it’s still burning. More than two months later, the Soberanes Fire is 99% contained at just over 132,000 acres (about 9/10 the size of Chicago).

This year’s big fires are mostly in Southern California: of the ten biggest fires this


The plants around the Hollywood sign? That’s chaparral. (Photo: T. Hoffarth)

year, eight are in Southern California (though the biggest is on the Central Coast). This is the opposite from last year: nine out of ten were in Northern California. Most Southern California fires are not forest fires (neither were several of last year’s biggest fires). Instead, these fires blaze through the steep, dense shrublands known as chaparral. This year, chaparral-covered Southern California should have our attention. So why are so many media outlets still focusing on the stories of Northern forest fires?

Let me be clear: big fires, including chaparral fires, always make the news—even the national and international news. In fact, I’d wager the majority of news articles about California fires are actually about chaparral fires—they are closest to where people live (chaparral surrounds most of the big cities) and some of the hardest to fight (dense vegetation, steep slopes).

But news articles about fire fall into two types—or at least, two parts. There’s the incident part–we hear about fire size, ignition source, number of firefighters, people evacuated, structures damaged. Then there’s the big picture part—why are we seeing so many big, hard to control fires today? How do these fires fit into long term trends?

News articles that focus on chaparral fires get the first part right. Here’s an example, from last year’s Rocky Fire. But reporters struggle when it comes time to step back and put these fires in the broader context of the modern problems of fire in the West. They throw in references to fire suppression (here’s one example) and note that prescribed fire can help–even when most evidence suggests that this is not the case for these regions. Likewise, bigger picture stories in the science sections of the New York Times or LA Times tend to treat all wildfires as if they are forest fires under conditions like those found in the Sierra Nevada.

Fires in forests and in chaparral or other vegetation types have a lot in common, and understanding the basics of what generates and shapes wildfire (eg. available fuels, ignition sources, weather, topography) is helpful in any environment. But just as different habitats have different plants, animals, and amounts of rainfall, so too do they have different fire behavior. This isn’t just a comparison—the kind of plants and the amount of rainfall directly determine the kind of fire you get in a given system.


A chaparral hillside regenerating after the Wragg Fire in 2015. (Photo: A. Weill)

Why is it so important to recognize this difference? When it comes to managing fire for the benefit of people, infrastructure, and natural resources, the kind of fire you get in that system matters. As noted above, some strategies that work well in one system are counterproductive or inefficient in another. Managing wildfire is expensive, in both dollar amounts and costs for human life and wellbeing, and we can’t afford to keep using a one-size-fits-all approach.

In particular, we need to bring more attention to understanding the specific dynamics of chaparral and other non-forested ecosystems in California. Many big, destructive fires aren’t in forests, as noted above, and most people in California don’t live in forested areas–they live in the big cities, surrounded by hillsides covered in dense chaparral shrubs. As of 2010, the five most populous California counties are in Southern California, where the most common vegetation type is chaparral or desert. I’ve heard the argument that wildfire is only a problem when people come into contact with it—when they build their houses in fire-prone areas. If the wildfire problem is a people problem, its center should be Southern California and other highly populated areas, not the Sierra Nevada.

I don’t mean to suggest that forests are not important, or that we should stop talking about the issues they face. Indeed, forests take up much more land area than chaparral in California. Instead, I want fire science communicators to approach their work a bit differently. First, we should make a greater effort to consider the ecosystem context of the wildfires we write about.  Second, we should elevate the importance of understanding and finding solutions for fire issues in the systems where most people actually live.

There are signs that fire science communicators are starting to do this—a recent article on fire and beetles by KQED took pains to discuss how region-specific differences could matter, and an article in the New York Times mentioned how shrublands were different from forests at the end. In September, there was a panel on Living With Fire at the Society for Environmental Journalists meeting in Sacramento that stressed the differences between fire in Northern and Southern California.

But caveats in the last few sentences of an article, as was the case with the NYT article, aren’t very effective. Most people won’t read that far—they’ll read the headline and introduction, which are designed to draw readers in. The aforementioned NYT article has a headline focused on prescribed burning yet starts with a discussion of big chapparal-driven blazes. Does it matter that the end of the article asserts that prescribed burning isn’t a solution for Southern California when the first half of the article implied otherwise?

Chaparral fires need their own stories—they can’t be a tag on or exception. And newsmakers seem to be aware that something called chaparral plays a role in many big, destructive fires—chaparral is the star of the incident-focused stories. Why is it so hard, then, to tell their scientific and management stories?

My answer: it comes down to good storytelling.

The narratives about fire suppression in the Sierra are so compelling, and in the end, so satisfying. The story of fire in the Sierra is a great story. It has lots of interesting characters (the Europeans who thought fire was bad and didn’t know any better, environmentalists who decided fire was natural and good decades later, Smokey Bear as a surprise villain, Native Americans who knew the truth all along), it has neat and understandable science (fire behavior and plant adaptations), and it has a terrific setting (Yosemite, Lake Tahoe, everyone’s favorite hiking spots). But most importantly, this story ends with solutions. People are left to feel optimistic that we can undo the damage we’ve done through prescribed burns, letting more wildfires burn before suppressing them, and carefully planned thinning (never mind the fact that we haven’t done a very good job of implementing these solutions in the decades that we’ve known about them).


We love to tell fire stories about places like Yosemite National Park. (Photo: A. Weill)

In our shrubby backyards? That story doesn’t have a lot going for it. Humans caused most of the fires, and they still do. Fires in chaparral have probably always been hot and destructive. Suppression wasn’t nearly as effective as it was in the forests, and we get more fires, not fewer, as coastal cities grow. Prickly ceanothus branches aren’t nearly as lovable as a huggable Jeffrey pine that smells like butterscotch. There’s already plenty of fire on the ground, and there’s not much evidence that thinning and burning are effective. What’s the solution? Move away, build your home out of different materials, don’t start fires. Learn to live with fire, or leave. Prescribed fire and fire use are somebody else’s job. When there’s not a lot that fire management can do, the burden of living in the wildland-urban interface falls more squarely on the homeowner’s shoulders.

That’s a pretty negative narrative, and it’s no wonder these stories don’t catch on. Yet it doesn’t need to be written that way. We can learn to tell a good story about fire in chaparral or other non-forest systems–the long history of fire and people along the coast, the plants and animals so adapted, the importance of climate and population growth and erosion and flooding. Chaparral fire has its own history and characters, from Native American fire use over thousands of years to to residents of San Diego evacuated in the 2003 Cedar Fire–the largest in recorded California history. Ceanothus shrubs may be stiff and prickly, but they have beautiful flowers that color the hillsides in the early spring. As for solutions—even if the best strategies we have now for living with fire in Southern California aren’t so appealing, it’s likely that there are tools and strategies that we don’t even know about yet that would come about with further research and discussion. But there’s no chance for this until we bring more focus to chaparral fires and stop conflating them with forest fires.


Chaparral has its own stories. (Photo: A. Weill)


An unexpected herbivore

Columbines are toxic! Like larkspurs, columbines are supposedly toxic to most livestock and humans. So say the books. This rabbit doesn’t listen to the books. (The internet, in its infinite wisdom, says that the eastern species has edible – to human – flowers, so maybe the rabbit is just rather tech-savvy)

I actually suspect that the roots and leaves may be somewhat toxic but the reproductive parts, including the flowers and pedicels (which the same rabbit eats in the next video!), are not. Deer also eat them, especially in one particular population, which I’ve mostly stopped using for experiments because of it. Wild speculation aside, just thought I’d share the video as I got a kick out of it.

Also, a question – is this a brush rabbit (Sylvilagus bachmani), a European rabbit (Oryctolagus cuniculus) or a black-tailed jackrabbit (Lepus californicus)? . A terrible still of the tail from the video is below. I feel a bit silly that I can’t even conclusively get it to genus. I’d be kicking myself pretty seriously if I couldn’t get a dragonfly, bird, wildflowers, or butterfly to genus and really this should be far easier!


useR! talk on teaching R

Here is a video recording of my talk from useR! 2016 on teaching R. It’s nominally about teaching a lot of students in an intensive format, but I think almost everything translates to traditional classes. If for whatever reason this video isn’t working out for you, here is the source.

This talk was just one in a great session. I’d highly recommend:

read more