AI Assistants for Scientific Coding

Author

Chris Brown

Published

August 25, 2026

0.1 Summary

If you are doing data analysis you are probably using language models (e.g. ChatGPT) to help you write code, but are you using them in the most effective way? Language models have different biases to humans and so make different types of errors. This book will cover how to use language models to learn scientific computing and conduct reliable environmental analyses. The book is reference material for a 1-day workshop I teach.

I will cover:

  • How to use different software tools, from simple interfaces like ChatGPT to advanced tools that can run and test code by themselves and keep going until the analysis is complete (and even written up).
  • Best practice prompting techniques that can dramatically improve model performance for complex data analysis
  • Applying language models to common environmental applications such as generalised linear models
  • Security, data privacy and the limitations of these tools for scientific work

The content I’ll teach is suitable for anyone using scientific computing (e.g. R, Python) to do data analysis.

Examples will be in marine conservation science using the R language, but the methods are general to any field. The AI software is also general to any programming language and we won’t be doing much actual coding (the AI does that!) so readers can follow along in other languages if they prefer. To follow the practical applications you will need to have some experience in scientific computing (e.g. R or Python).

0.2 Citation for book

Please consider citing my accompanying article if you are using the advice in this book:

Brown, C.J. & Spillias, S. (2026). Prompting large language models for quality ecological statistics. Methods in Ecology and Evolution. [https://doi.org/10.1111/2041-210x.702670 (Brown and Spillias 2026)

If you are using the material on agents and specification sheets, the companion study is:

Brown, C.J., Aitken, J., Takyi, R. & Tisseaux-Navarro, A. (2026). Automating Ecological and Fisheries Modelling With Agentic AI. Fish and Fisheries. [https://doi.org/10.1111/faf.700791 (Brown et al. 2026)

0.3 Who should read this book?

The book is for: anyone who currently uses R, from intermittent users to experienced professionals. The book is not suitable for those that need an introduction to R and I’ll assume students know at least what R does and are able to do tasks like read in data and create plots. If you need an introduction to R then I recommend you learn it without AI first.

0.4 Is the book up to date?

The large language model industry is changing rapidly. I’ll periodically update this book to keep up with developments. I also recommend checking out Large Language Model tools for R by Luis D. Verde Arregoitia. This is a living list of tools and R packages for using LLMs.

This version of the book was last updated on the date shown at the top of this page.

0.5 About Chris

I’m an Associate Professor of Fisheries Science at University of Tasmania. I specialise in data analysis and modelling, skills I use to better inform environmental decision makers. R takes me many places and I’ve worked with marine ecosystems from tuna fisheries to mangrove forests. I’m an experienced teacher of R. I have taught R to hundreds of people over the years, from the basics to sophisticated modelling and for everyone from undergraduates to my own supervisors.

0.6 Software you’ll need for this workshop

You will need some time to set up the software. You may also need IT help if your computer is locked down. See Setup for more detailed instructions.

0.7 Book overview

The book is organised as short, self-paced modules, grouped into bigger sections.

  • Introduction: Strengths, weaknesses and common failure modes of language models when used for programming and data analysis.
  • Setup: Step‑by‑step software installation, recommended environments (R, Python, editors), and brief troubleshooting tips.
  • Section 1: Line-by-line code completion: Inline completions, comment-driven code, Copilot settings, Gander, and a discussion of the strengths and weaknesses of this approach.
  • Section 2: Agents: Agent options, how agents work, security risks, a first agent example, and a series of modules on prompting and working with agents.
  • Section 3: AI in workflows: My suggested three-step workflow — select a statistical approach, plan implementation, write the code — plus specification sheets.
  • Section 4: Security, data privacy and cloud agents: Concrete security risk examples, Claude Code for web, bash sandboxing, keeping data secure from the cloud, and limitations.
  • Section 5: Customising agents: Skills and sub-agents — packaging reusable instructions and delegating specialised roles, worked through a GLM analysis, plotting, and methods write-up.
  • Section 6: Agentic engineering for data analysis: Tests and verification, red-green TDD, and using simulated data as a verification step.
  • Section 7: LLM access via API: API keys, how ellmer talks to a provider, chat, a DIY chatbot, building your own minimal agent, and a literature review example.
  • Section 8: Running local models: installing Ollama, the hardware you’ll need, choosing a model, and three applications — autocomplete, agentic coding, and processing text and literature in R.
  • Appendix — Code and data: Code snippets, data access links and supporting scripts used in the book.

0.8 Data

We’ll load all data files directly via URL in the workshop notes. So no need to download any data now. Details on data attribution are below.

0.8.1 Benthic cover surveys and fish habitat

In this course we’ll be analysing benthic cover and fish survey data. These data were collected by divers doing standardised surveys on the reefs of Kia, Solomon Islands. These data were first published by Hamilton et al. 2017 (Hamilton et al. 2017), who showed that logging of forests is causing sedimentation and impacting habitats of an important fishery species.

In a follow-up study Brown and Hamilton 2018 developed a Bayesian model that estimates the size of the footprint of pollution from logging on reefs.

0.9 How the book was written

The book is a mixture of my original writing, voice dictation and Claude’s writing. I’ve written new sections and repurposed my own blog posts, papers and workshop notes for use here. I also often voice dictate using a speech-to-text app, then use Claude to clean that dictation up for the page.

Some sections are written by Claude where I think a topic is important to cover, but I have not had time to update/write them myself. However, I do due diligence editing on everything, to remove AI slop and check for accuracy.