Back to News for Developers

Why did Marketing Science at Meta develop marsci, an internal R library?

June 14, 2023ByDani Rojas

How can we make sure that a new development or insight uncovered by one person effectively transfers to the rest of the team? In small teams we often write single functions, scripts and templates to optimize our personal workflows; but, as the team grows, different people start developing their own tools and code to solve similar problems. The Marketing Science (marsci) R library addresses this issue by centralizing and supporting daily analytical and technical tasks.

This R library started out as a personal repository where I could save queries and repetitive code related to my role as Marketing Science Partner at Meta back in December 2019. As I grew my personal library and shared it with others, it became increasingly useful and came to the attention of my former manager, and afterward, our regional director and VPs, all of whom fully supported the development of the project.

Setting up an R library helped our team address these three main challenges:

  1. Duplication of work within the team, both in writing the tools and reviewing code.
  2. Lack of transparency about how tools are written and lack of documentation, often resulting in bugs or incorrect usage.
  3. Difficulty sharingnew developments with other users, slowing down productivity and missing opportunities.

In this post, I’ll share insights from developing the marsci R library and provide a few tips for developing your own.

How R libraries address scalability challenges

R is an open-source programming language and environment originally designed for statistical computing and graphics. In the last decade, R has become one of the most relevant languages for analytics and data science. It’s a flexible, scalable and popular open-source tool used by analysts around the world.

R packages are the basic units of reproducible code. They can include functions, documentation, data, tests, add-ins, vignettes, R markdown and other templates. By enabling a collaborative, scalable and reproducible system using R packages, we are able to work and collaborate more efficiently.

The marsci R library is an internal R package independently developed and maintained by our team to provide solutions for our daily workflow and common tasks. Think of it as a tool case with tools designed specifically for our team’s needs.

It allows our work to be:

  1. Collaborative: It centralizes our team’s knowledge into a collaborative quality code repository that is constantly growing, adapting to new priorities, and improving.
  2. Scalable: It’s maintained and reviewed by few peers, deployed to be used by any team member and cross-functional.
  3. Reproducible:It saves time by automating and simplifying typical tasks, with robust replicable analysis and reporting.

Usage and impact of the marsci R library

Since the beginning, and now more than ever, the marsci R library aligns with the goals of both Meta and Marketing Science, including Meta’s Year of Efficiency for 2023.

One of our mottos is: "It's not coding, but running code." We have numerous senior users in our team with no coding experience that use our marsci R library with little to no guidance to get analyses results and useful outputs. We constantly enable non-technical users to run functions, so that when customizing the arguments, they get exactly the output they need, without actually having to code. We’ve developed a good user experience by trying to think like them, returning meaningful errors that provide potential solutions, automating inputs to reduce decisions and solving general pain points for them.

Here are a few use cases enabled through the marsci R library that have already helped hundreds of internal researchers and analysts make their jobs easier and collaborate with other colleagues:

  • Users can query data in a safe, friendly, flexible and peer-reviewed way.
  • It has the ability to run robust meta-analyses (descriptive, regression and statistical).
  • Deliver auto-approved for external sharing automated PowerPoint reports (meta-analyses, aggregated lift studies results, simulations, among others).
  • It can analyze and calculate elasticity, ads contamination, reach overlap, power calculations, and more.
  • It has internal functions to easily deal with internal infrastructure issues, dictionaries, and other helper functions for our users.

The marsci R library has also been used to enable a number of public-facing and external projects. To name a couple, studies showing that Connected Brands drive deeper brand outcomes (compared with non-connected campaigns), and how Social Cause Marketing Campaigns bring consumers closer to brands.

Usage and impact of the marsci R library

I’d like to share a few learnings and tips for you and your team that will help develop your own R library:

  • Impact: Prioritize your asks and backlogs based on impact. Once your package starts getting popular, everyone will want to have their use cases implemented and automated. I like to keep an Asana with a “backlogs,” “ready to go,” “in progress” and “completed” kind of structure. This structure is especially useful for following up on requests, status updates and dependencies. I also recommend surveying your team every once in a while to uncover pain points and new challenges.
  • Updates: Share all relevant changes deployed with your team and stakeholders. For marsci R library, we have an internal group where I share all relevant new features, bugs fixed and changes sorted by importance, and keep users updated. I also tag people as necessary to keep them up to date. It’s important you have a clear and tactical go-to-market strategy to train, educate and inform your team (users and non-users) of the marsci R library’s capabilities. Having regional points of contact definitely helps to achieve these objectives.
  • UX: Always keep the user in mind whenever making decisions on default values, potential errors on inputs, wordings on the documentation, or other fixes. If the users love the product, they’ll not only start using the solution, but also recommend it to everyone else on the team.
  • Logs: If possible, log the usage of each function and parameter. You’ll be able to measure usage, adoption, impact and help debug. This is how I know which users are new, so we can automatically add them to our internal group and measure timings.
  • Version control: Leverage git and version control systems to collaborate with other developers and team members, making sure to clearly update the package versions in case there are issues when deploying new versions.
  • Documentation: Even though it’s obvious, having documentation that is clear, easy-to-understand and up to date is as important as it gets. By default, R packages have all functions and parameters updated, but be sure to specify what each argument does, what the possible inputs/ranges/values are, and how these change the outputs. Also, having a nice cheat sheet and some relevant vignettes with common use cases helps!
  • Infrastructure: Get to know your infrastructure and its limitations, especially if you (ideally) are deploying the package to be updated in all available servers to all users daily. Also, get an engineer friend or two to agree on best practices for security and deployment.
  • Reference: Since the marsci R library was one of the first internal packages to be created by its own team, it has been a useful reference for other teams to check. Make sure you check out other external and internal packages to see how they work!
  • Read: Everything else has already been said on developing R packages. Check out “R Packages” by Hadley Wickham and Jenny Bryan and “Developing Packages with the RStudio IDE” on the Posit Support blog.

I highly encourage you and your team to start gathering knowledge to share scalable and reproducible solutions using R libraries. Go and redefine your team’s way of working!

The marsci R library is, and always will be, a solution built for MSPs by MSPs. It will continue to empower us with collaborative, scalable and reproducible solutions to help clients and markets grow using data and science.

This blog was written in collaboration with Bernardo Lares, who created the marsci R library in 2019.