Object of Type Closure is Not Subsettable

I started using R in 2004. I started using R religiously on the day of the annular solar eclipse in Madrid (October 3, 2005) after being inspired by David Hunter’s talk at ADASS.

It took me exactly 4,889 days to figure out what this vexing error means, even though trial and error helped me move through it most every time it happened! I’m so moved by what I learned (and embarrassed that it took so long to make sense), that I have to share it with you.

This error happens when you’re trying to treat a function like a list, vector, or data frame. To fix it, start treating the function like a function.

Let’s take something that’s very obviously a function. I picked the sampling distribution simulator from a 2015 blog post I wrote. Cut and paste it into your R console:

sdm.sim <- function(n,src.dist=NULL,param1=NULL,param2=NULL) {
   r <- 10000  # Number of replications/samples - DO NOT ADJUST
   # This produces a matrix of observations with  
   # n columns and r rows. Each row is one sample:
   my.samples <- switch(src.dist,
	"E" = matrix(rexp(n*r,param1),r),
	"N" = matrix(rnorm(n*r,param1,param2),r),
	"U" = matrix(runif(n*r,param1,param2),r),
	"P" = matrix(rpois(n*r,param1),r),
        "B" = matrix(rbinom(n*r,param1,param2),r),
	"G" = matrix(rgamma(n*r,param1,param2),r),
	"X" = matrix(rchisq(n*r,param1),r),
	"T" = matrix(rt(n*r,param1),r))
   all.sample.sums <- apply(my.samples,1,sum)
   all.sample.means <- apply(my.samples,1,mean)   
   all.sample.vars <- apply(my.samples,1,var) 
   par(mfrow=c(2,2))
   hist(my.samples[1,],col="gray",main="Distribution of One Sample")
   hist(all.sample.sums,col="gray",main="Sampling Distribution\nof
	the Sum")
   hist(all.sample.means,col="gray",main="Sampling Distribution\nof the Mean")
   hist(all.sample.vars,col="gray",main="Sampling Distribution\nof
	the Variance")
}

The right thing to do with this function is use it to simulate a bunch of distributions and plot them using base R. You write the function name, followed by parenthesis, followed by each of the four arguments the function needs to work. This will generate a normal distribution with mean of 20 and standard deviation of 3, along with three sampling distributions, using a sample size of 100 and 10000 replications:

sdm.sim(100, src.dist="N", param1=20, param2=3)

(You should get four plots, arranged in a 2×2 grid.)

But what if we tried to treat sdm.sim like a list, and call the 3rd element of it? Or what if we tried to treat it like a data frame, and we wanted to call one of the variables in the column of the data frame?

> sdm.sim[3]
Error in sdm.sim[3] : object of type 'closure' is not subsettable

> sdm.sim$values
Error in sdm.sim$values : object of type 'closure' is not subsettable

SURPRISE! Object of type closure is not subsettable. This happens because sdm.sim is a function, and its data type is (shockingly) something called “closure”:

> class(sdm.sim)
[1] "function"

> typeof(sdm.sim)
[1] "closure"

I had read this before on Stack Overflow a whole bunch of times, but it never really clicked until I saw it like this! And now that I had a sense for why the error was occurring, turns out it’s super easy to reproduce with functions in base R or functions in anyfamiliar packages you use:

> ggplot$a
Error in ggplot$a : object of type 'closure' is not subsettable

> table$a
Error in table$a : object of type 'closure' is not subsettable

> ggplot[1]
Error in ggplot[1] : object of type 'closure' is not subsettable

> table[1]
Error in table[1] : object of type 'closure' is not subsettable

As a result, if you’re pulling your hair out over this problem, check and see where in your rogue line of code you’re treating something like a non-function. Or maybe you picked a variable name that competes with a function name. Or maybe you got your operations out of order. In any case, change your notation so that your function is doing function things, and your code should start working.

But as Luke Smith pointed out, this is not true for functional sequences (which you can also write as functions). Functional sequences are those chains of commands you write when you’re in tidyverse mode, all strung together with %>% pipes:

Luke’s code that you can cut and paste (and try), with the top line that got cut off by Twitter, is:

fun1 <- . %>% 
    group_by(col1) %>% 
    mutate(n=n+h) %>% 
    filter(n==max(n)) %>% 
    ungroup() %>% 
    summarize(new_col=mean(n))

fun2 <- fun1[-c(2,5)] 

Even though Luke’s fun1 and fun2 are of type closure, they are subsettable because they contain a sequence of functions:

> typeof(fun1)
[1] "closure"

> typeof(fun2)
[1] "closure"

> fun1[1]
Functional sequence with the following components:

 1. group_by(., col1)

Use 'functions' to extract the individual functions. 

> fun1[[1]]
function (.) 
group_by(., col1)

Don’t feel bad! This problem has plagued all of us for many, many hours (me: years), and yet it still happens to us more often than we would like to admit. Awareness of this issue will not prevent you from attempting things that give you this error in the future. It’s such a popular error that there have been memes about it and sad valentines written about it:

SCROLL DOWN PAST STEPH’S TWEET TO SEE THE JOKE!!

(Also, if you’ve made it this far, FOLLOW THESE GOOD PEOPLE ON TWITTER: @stephdesilva @djnavarro @lksmth – They all share great information on data science in general, and R in particular. Many thanks too to all the #rstats crowd who shared in my glee last night and didn’t make me feel like an idiot for not figuring this out for ALMOST 14 YEARS. It seems so simple now.

Steph is also a Microsoft whiz who you should definitely hire if you need anything R+ Microsoft. Thanks to all of you!)

Lack of Alignment is an Organizational Disease. Here are the Symptoms.

Streamlines on a field. Created using the pracma package in R.

Like a champion rowing team, your organization needs to make sure everyone is working together, engaged in synchronized work and active collaboration, and not working at cross-purposes.

But like risk management, working on alignment can seem like a luxury. No one really has time to slow down and make sure everyone’s moving in the same direction. And besides, alignment just happens naturally if each functional area knows what they’re supposed to be working on… right?

Neither of these statements are, of course, true. Synchronizing people and processes – and making sure they’re aware of the needs and desires of real customers instead of cardboard personas – takes dedicated effort and a commitment from senior leaders. There are other critical impacts too: lack of alignment negatively impacts not only project outcomes – but also professional relationships and the bottom line.

An Example of Diagnosing Misalignment

Although alignment is a many-to-many problem, and requires you to look at relationships between people in all your functional areas, a January 2018 survey from Altify examined one part of the organizational puzzle: alignment between sales and marketing. This is a big one, because sales teams use marketing materials to understand and sell the product or service your company offers. Their survey of 422 enterprise-level executives and sales leaders showed that:

  • 74% of marketers think they understood customer needs, but only 44% of sales people in their organizations agreed
  • 71% of marketers think sales and marketing are aligned, but only 59% of sales people in their organizations agreed

These differences may seem small, but they reveal a lack of alignment between sales and marketing. One group thinks they “get it” – while people in the other group are just shaking their heads.

Symptoms of Misalignment

…include things like:

  • Vague Feelings of Fear. Your organization has a strategic plan (knows WHAT it wants to do), but there is little to no coordination regarding HOW people across the organization will accomplish strategic objectives. You know what KPIs you’re supposed to deliver on, but you don’t know how exactly you’re supposed to work with anything in your power or control to “move the needle.”
  • Ivory Tower Syndrome. You’re in a meeting and get the visceral sense that things aren’t clear, or that different people have different expectations for a project or initiative. But you’re too nervous or uncertain to ask for clarification – or maybe you do ask, but you get an equally unclear answer. Naturally, you assume that everyone in the room is smarter than you (particularly the managers) so you shut up and hope that it makes sense later. The reality is that you may be picking up on a legitimate problem that’s going to be problematic for the organization later on.
  • Surprises. A department committed you to a task, but you weren’t part of that decision. Once you find out about it, the task just may not get done. Alternatively, you’ll have to adjust your workload and reset expectations with the stakeholders who will now be disappointed that you can’t meet their needs according to the original schedule. Or maybe work evenings and weekends to get the job done on time. Either way, it’s not pleasant for anyone.
  • Emergencies. How often are you called on to respond to something that’s absolutely needed by close of business today? How often are you expected to drop everything and take care of it? How often do you have to work nights and weekends to make sure you don’t fall behind?
  • Lead Balloons. In this scenario, key stakeholders are called into projects at the 11th hour, when they are unable to guide or influence the direction of an initiative. The initiative becomes a “dead man walking” that’s doomed to an untimely end, but since the organization has sunk time and effort into it, people will push ahead anyway.
  • Cut Off at the Pass. Have you ever been working on a project and find out – somewhere in the middle of doing it – that some other person or team has been working on the same thing? Or maybe they’ve been working on a different project, but it’s ultimately at cross purposes with yours. Whatever way this situation works out, your organization ends up with a pile of waste and potential rework.
  • Not Writing Things Down.You have to make sure everyone is literally on the same page, seeing the world in a similar enough way to know they are pursuing the same goals and objectives. If you don’t write things down, you may be at the mercy of cognitive biases later. How do you know that your goals and objectives are aligned with your overall company strategy? Can you review written minutes after key meetings? Are your organization’s strategic initiatives written and agreed to by decision makers? Do you implement project charters that all stakeholders have to sign off on before work can commence? What practices do you use to get everyone on the same page?

How do you fix it?

That’s the subject for more blog posts that will be coming this spring – as well as what causes misalignment in the first place (hint: it’s individual behaviors on an organizational scale). The good news is – misalignment can be fixed, and the degree of alignment can be measured and continuously improved. Sign up to follow this blog so you don’t miss the rest of the story.

What other symptoms of misalignment have you experienced?

Selecting Pages from a PDF to Make a New (Smaller) PDF

Sometimes small, simple tasks perplex me. Today’s challenge: I’m on Windows 10, and have a 53 page PDF of a journal. I need to make a NEW PDF that only contains pages 26 to 43 (my article) so I can send my article to a researcher who is requesting it. I know you can do this with Acrobat, but I don’t have Acrobat, and still would like to figure out how to make the smaller PDF. Here’s what I learned how to do today:

The Easy Way

  1. Go to https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
  2. Find the GREEN button that says “Download PDFtk FREE” and click it
  3. After the download finishes, right click on the .exe file and Run it
  4. When the installer starts, click on all the default options all the way through “Finish”
  5. When installation is finished, go to the search box in the bottom left of your screen
  6. Type “cmd” and hit Enter to open the terminal window
  7. Navigate to the directory that contains your original PDF. I first typed D: to get to my auxiliary hard drive, and then cd Scratch to get to D:\Scratch where my full journal PDF was stored.
  8. Use this code:
    pdftk yourlargefilename.pdf cat 26-43 output youroutputfilename.pdf

    (replacing YOUR filenames and YOUR starting and ending page numbers instead of 26 and 43)

  9. Launch a File Explorer window and navigate to the directory you used in Step 7 above. Open the PDF file and check to make sure it contains only the pages you expect.
  10. There are LOTS more things you can do with PDFtk from the Windows command line, like you did in Step 8. Lots of other options are described at https://www.pdflabs.com/docs/pdftk-cli-examples/

After I finished, I stumbled upon another way that didn’t require downloading a free program, and only uses Google Chrome. (Sometimes those free programs bother me. What a great way to infiltrate computers… offer a totally useful utility completely for free. Consequently, my advice to you is to download it at your own risk. Including these instructions is in no way a guarantee from me that PDFtk is safe.)

 

The Even Easier Way

  1. Open Google Chrome
  2. Type Ctrl-O (that’s the letter O, not the number zero)
  3. Select the large PDF file that you want to snip
  4. Your PDF will open in the browser… click on the beginning and ending pages, and capture the page numbers
  5. Click the print icon in the far upper right corner of your browser
  6. Click the “Change” button to change destination to “Microsoft Print to PDF”
  7. Click the second radio button under Pages, and specify the start and end pages separated by a dash (for me, 26-43)
  8. Click Print, and select a filename for your new, snipped file
  9. After the PDF is generated, navigate to the directory you saved it in during Step 8. Open the file and check it to make sure the pages are as you expect.

 

The Sad News

I tried to use the staplr package in R to snip my PDFs, but I couldn’t get it to work. Will try again some other time 🙁

Make Strategic Alignment Actionable with Baldrige

It can be difficult to focus on strategy when your organization has to comply with standards and regulations. Tracking and auditing can be tedious! If you’re a medical device manufacturer, you may need to maintain ISO 13485 compliance to participate in the supply chain. At the same time, you’ve got to meet all the requirements of 21 CFR 820. You’ve also got to remember other regulations that govern production and postmarket. (To read more about the challenges, check out Wienholt’s 2016 post.) There’s a lot to keep track of!

But strategy is important. Alignment is even more important! And in my opinion, the easiest way to improve alignment and get “Big Q” quality is to use the Baldrige Excellence Framework. It was developed by the Baldrige Performance Excellence Program, and is administered by NIST.

In Is Good, Good Enough for You? Taking the Next Step After ISO 9001:2015, former Baldrige Program Executive Director Harry Hertz outlines similarities and differences between ISO 9001:2015 and Baldrige. After examining complements, Harry shows how Baldrige helps organizations grow beyond the conformance mindset:

I have not shared all the commonalities of or differences between ISO 9001:2015 and the Baldrige Excellence Framework. Instead, I have tried to show the organizational possibilities of building on conformity assessment to establish a holistic approach for achieving excellence in every dimension of organizational performance today, with a look to the strategic imperatives and opportunities for the future. Baldrige helps an organization take this journey with a focus on process (55% of the scoring rubric) and results (45% of the rubric), recognizing that great processes are only valuable if they yield the complete set of results that lead to organizational sustainability… I encourage organizations that have not gone beyond conformity to take the next step in securing your future.

Read More Here! –>

Engagement: Why Too Much of a Good Thing Can Be Bad

Engagement is a goal for many organizations. In the January 2018 issue of Forbes, it’s described as a hallmark of successful business, a cultural cornerstone that reduces the risk of turnover while enhancing product quality, process quality, and customer satisfaction. Unfortunately, the same story also cites a Gallup poll from 2017 that found only 32% of workers are engaged — “involved in, enthusiastic about and committed to their work and workplace.” The majority are disengaged, a problem that management consultant and bestselling author Tom Peters has also noted.

When developing strategies for engagement, though, it’s important to remember that engagement, too, can go wrong. Enthusiasm for sports teams or political parties can become so driven by passion that judgment is clouded, and intense engagement in online social groups communities of practice can devolve into anger and name calling. Trolls on Twitter, for example, are highly engaged — but this is clearly not the kind of behavior organizations would ideally like to model or promote.

Cult members are also typically highly committed and engaged — in the most extreme cases, this engagement can be life-or-death. Heaven’s Gate in 1997, and Jim Jones’ Peoples Temple in Guyana in 1978, are two of the more tragic examples.

How can an organization protect against “bad engagement”? Evan Czaplicki (creator of the programming language Elm) reflected on this problem in the open source software development community in this amazing hour captured on YouTube. For years, open source has been plagued by highly engaged community members who interact with one another unconstructively, ultimately damaging the feelings of trust and cohesion that would help community members meet their goals.

Some of his recommendations to promote “good engagement” by steering away from the bad include:

  • Limiting the number of characters people have to respond with
  • Limiting the types of interactions that are possible, e.g. upvoting or downvoting content
  • Making it possible for people to express intent with their statements or comments
  • Helping people identify and communicate their priorities as part of the exchange (e.g. simplicity vs. extensibility, freedom vs. community building)

For more hints and tips, be sure to check out Evan’s presentation.

 

Additional Reading:

Czaplicki, E. (2018, September 27-28). The Hard Parts of Open Source. Strange Loop Conference. Available from https://www.youtube.com/watch?v=o_4EX4dPppA&t=3s

Kappel, M. (2018, January 4). How To Establish A Culture Of Employee Engagement. Forbes. Available from https://www.forbes.com/sites/mikekappel/2018/01/04/how-to-establish-a-culture-of-employee-engagement/#6ddb58de8dc4

 

The Achilles Heel of Customer Journey Mapping

Journeying through western Wyoming in August 2011. Image Credit: me.

Achilles was that guy in Greek mythology whose mother, when he was born, wanted to protect him soooo much that she held him by the heel and dipped him in the power-giving waters of the River Styx — making him bullet proof (and much more; no bullets then), except at the heel, because for some reason she didn’t think about just dunking him a few inches deeper. Maybe she didn’t want to get her hand wet? Who knows. (In the research literature this is called perverse unintended consequences — it happens in business too. You try to make an improvement or protect against a particular hazard and oops, you made it worse.)

Customer Journey Maps (CJM)

I’ve been reading a lot about the Customer Journey Maps (CJM) technique used in marketing (see Folstad & Kvale (2018) for a fantastic and comprehensive review). It formalizes the very good suggestion that when you’re trying to figure out how to engage with prospects, you should put yourself in their shoes. Empathize with them. Figure out what they need, and when they need it. Then, identify how your company can not only meet them there — but connect with them in a compelling way.

CJM also goes beyond conceptual modeling. For example, Harbich et al (2017) uses Markov models to predict the most likely path and timing of a customer’s journey. Bernard & Andritsos (2018) mine actual customer journeys from sales force automation systems and use them in a Monte Carlo like way to uncover patterns. There’s even a patent on one method for mining journey data.

Benefits of Journey Maps

Annette Franz says that “done right, maps help companies in many ways, including to…

  • Understand experiences.
  • Design [new] experiences.
  • Implement and activate new experiences.
  • Communicate and share experiences.
  • Align the organization… get executive commitment for the customer experience (CX) strategy, get organizational adoption of the customer-centric focus, provide a line of sight to the customer for employees, and help employees understand how they impact the experience.”

But like Achilles, Customer Journey Mapping has a vulnerable spot that can wipe out all its potential benefits. (Fortunately, success lies in the way your organization wields the tool… so there’s a remedy.)

The Achilles Heel of CJM

Here’s the problem: creating a journey map does indeed ensure that you focus on the customer, but does not ensure that you’re focusing on that customer’s experience. Diagnosing Voice of the Customer (VoC) is hard [long explanation; shorter explanation], and there are tons of ways to do it! Through journey mapping, you may accidentally be focusing on your company’s experience of that customer throughout the stages of the journey. 

Diagnosing the Symptoms

How can you tell? Here’s a non-exhaustive list of ways to diagnose the symptoms, based on recent research and observing companies who do this since about 2009 (please add in the comments if you’ve observed any other ones):

  • Do you ever hear “How can we move the customer from [this stage] to [the next stage]?”
  • … or “How do we get more customers to join us [at this stage of the journey]?”
  • … or maybe “How can we get customers to [take this action] [at this stage of the journey]?”
  • Does your customer journey address differences in customer personas, or do you have a one-size-fits-all map? Rosenbaum et al (2016) says “We contend that most customer journey maps are critically flawed. They assume all customers of a particular organization experience the same organizational touchpoints and view these touchpoints as equally important.”
  • Do you systematically gather, analyze, and interpret data about what your current customers are experiencing, or do you just kind of guess or rely on your “experience”? (Hint: subconscious biases are always in play, and you’ll never know they’re there because they are subconscious).
  • Do you systematically gather, analyze, and interpret data about what your prospects would benefit from experiencing with/through you, or do you just kind of guess or rely on your “experience”?
  • Do you focus on ease of use over utility? (Just like perfect is the enemy of perfectly OK, easy can be the enemy of possible if you’re not careful. This often shows up in the journey mapping process.)

Like I mentioned earlier, this is definitely not a comprehensive list.

The Solution

What’s the solution? ASK. Ask your customer what they need. Find out about their pain points. Ask them what would make it easier for them to do their job. Finally, ask them if you’re getting it right! And even though I said “customer” — I do mean you should ask more than one of them, because needs and interests vary from person to person and industry to industry. Just interacting with one customer isn’t going to cut it.

Ask early, ask often! (As people learn and evolve, their needs change.)

Improving the Method

How can we improve the quality of customer journey mapping? Share your insights and lessons learned! CJM is a promising technique for helping organizations align around empathetic value propositions, but just like agile methods, it’s got to be applied strategically and deliberately… and then checked on a continuous basis to make sure the map is in tune with reality.

Improve Writing Quality with Speaking & Storyboarding

For a decade, I supervised undergrads and grad students as they were completing writing projects: term papers, semester projects, and of course — capstone projects and thesis work. Today, I’m responsible for editing the work of (and mentoring) junior colleagues. The main lesson I’ve learned over this time is: writing is really hard for most people. So I’m here to help you.

Me, Reviewing Someone Else’s Work

If I had a dollar for every time this scenario happened, I’d… well, you get my point:

ME (reading their “final draft”): [Voice in Head] Huh? Wow, that sentence is long. OK, start it again. I don’t understand what they’re saying. What are they trying to say? This doesn’t make any sense. It could mean… no, that’s not it. Maybe they mean… nope, that can’t be it.

ME: So this sentence here, the one that says “Start by commutating and telling the story of what the purpose of the company’s quality management software is, the implementation plans and the impact to the current state of quality roles and responsibilities for everyone involved.”

THEM (laughing): Oh! Commutating isn’t a word. I meant communicating.

ME: Have you tried reading this sentence out loud?

THEM (still laughing, trying to read it): Yeah, that doesn’t really make sense.

ME: What were you trying to say?

THEM: I was trying to say “Start by explaining how quality management software will impact everyone’s roles and responsibilities.”

ME: Well, why don’t you say that?

THEM: You mean I can just say that? Don’t I need to make it sound good?

ME: You did just make it sound good when you said what you were trying to say.

What Just Happened?

By trying to “make it sound good” — it’s more likely that you’ll mess it up. People think speaking and writing are two different practices, but when you write, it’s really important that when you speak it out loud, it sounds like you’re a human talking to another human. If you wouldn’t say what you wrote to someone in your target audience in exactly the way that you wrote it, then you need to revise it to something you would say.

Why? Because people read text using the voice in their heads. It’s a speaking voice! So give it good, easy, flowing sentences to speak to itself with.

What Can You Do?

Here are two ways you can start improving your writing today:

  1. Read your writing out loud (preferably to someone else who’s not familiar with your topic, or a collaborator). If it doesn’t sound right, it’s not right.
  2. Use a storyboard. (What does that mean?)

There are many storyboard templates available online, but the storyboard attached to this post is geared towards developing the skills needed for technical writing. (That is, writing where it’s important to support your statements with citations that can be validated.) Not only does citing sources add credibility, but it also gives your reader more material to read if they want to go deeper.

Storyboarding

The process is simple: start by outlining your main message. That means:

  1. Figure out meaningful section headers that are meaningful on their own.
  2. Within each section, write a complete phrase or sentence to describe the main point of each paragraph or small group of paragraphs
  3. For each phrase or sentence that forms your story, cut and paste material from your references that supports your point, and list the citation (I prefer APA style) so you don’t forget it.
  4. Read the list of section headers and main points out loud. If this story, spoken, hangs together and is logical and complete — there’s a good chance your fully written story will as well.

Not all elements of your story need citations, but many of them will.

Next Steps

When the storyboard is complete, what should you do next? Sometimes, I hand it to a collaborator to flesh it out. Other times, I’ll put it aside for a few days or weeks, and then pick it up later when my mind is fresh. Whatever approach you use, this will help you organize your thoughts and citations, and help you form a story line that’s complete and understandable. Hope this helps get you started!

STORYBOARD (BLANK)

STORYBOARD (PARTIALLY FILLED IN)

« Older Entries Recent Entries »