Learn R Programming

astronomyengine

The astronomyengine R package provides R bindings to the Astronomy Engine. It bundles an up-to-date copy of the Astronomy Engine C library by Don Cross as a single-file header + source pair. This provides low-level access to the C library so that other R packages can link against it via LinkingTo without bundling their own copy.

Astronomy Engine is an open-source library for calculating positions of the Sun, Moon, and planets, and for predicting astronomical events such as rise/set times, lunar phases, equinoxes, solstices, eclipses, and transits. It is based on the VSOP87 planetary model and is accurate to within approximately ±1 arcminute.

Installation

You can install the released version of astronomyengine from CRAN with:

install.packages("astronomyengine")

And the development version from GitHub with:

# install.packages("pak")
pak::pak("mitchelloharawild/astronomyengine")

Usage

library(astronomyengine)
# All functions accept a `POSIXct` time as input.
# Here we use a reference time of 2025-02-19 12:00 UTC for all examples.
now <- as.POSIXct("2025-02-19 12:00:00", tz = "UTC")

The R functions and documentation are designed to be as similar as possible to the C API. Therefore the most comprehensive resource for learning how to use the package is the Astronomy Engine C API documentation. If you need support for how to use the package, I suggest that you also search for information about the underlying C library.

Next sunrise

Find the next sunrise at a given location — here, Sydney Observatory (latitude −33.87°, longitude 151.21°):

astro_search_rise_set(
  astro_body[["SUN"]], now,
  latitude = -33.8688, longitude = 151.2093
)
#> [1] "2025-02-19 19:34:50 UTC"

Current moon phase

astro_moon_phase() returns the Moon’s phase as an angle in degrees: 0° = new moon, 90° = first quarter, 180° = full moon, 270° = third quarter.

astro_moon_phase(now)
#> [1] 256.4968

Next full moon

Search for the next time the Moon reaches a specific phase angle. Use 180° for a full moon:

astro_search_moon_phase(180, now, limit_days = 30)
#> [1] "2025-03-14 06:55:19 UTC"

Solar eclipse

Find the next solar eclipse visible anywhere on Earth:

eclipse <- search_global_solar_eclipse(now)
eclipse
#> $status
#> [1] 0
#> 
#> $kind
#> [1] 2
#> 
#> $peak
#> [1] "2025-03-29 10:47:25 UTC"
#> 
#> $distance
#> [1] 6637.035
#> 
#> $latitude
#> [1] NaN
#> 
#> $longitude
#> [1] NaN

The kind field indicates the eclipse type: 0 = partial, 1 = annular, 2 = total. This total solar eclipse peaks on 2025-03-29.

Note: latitude and longitude in the eclipse result indicate the point of greatest eclipse on Earth’s surface. These are only populated for annular eclipses; for total eclipses they will be NaN.

Transit of Mercury

A transit occurs when Mercury passes directly between the Earth and the Sun. These are rare — the next one after February 2025 is in November 2032:

astro_search_transit(astro_body[["MERCURY"]], now)
#> $start
#> [1] "2032-11-13 06:41:48 UTC"
#> 
#> $peak
#> [1] "2032-11-13 08:54:14 UTC"
#> 
#> $finish
#> [1] "2032-11-13 11:06:53 UTC"
#> 
#> $separation
#> [1] 9.594123

Equinoxes and solstices

astro_seasons() returns all four seasonal turning points for a given year:

astro_seasons(2025)
#> $mar_equinox
#> [1] "2025-03-20 09:01:26 UTC"
#> 
#> $jun_solstice
#> [1] "2025-06-21 02:42:17 UTC"
#> 
#> $sep_equinox
#> [1] "2025-09-22 18:19:34 UTC"
#> 
#> $dec_solstice
#> [1] "2025-12-21 15:03:03 UTC"

Using the C library from another package

To use the Astronomy Engine C API from another R package:

  1. Add astronomyengine to both Imports and LinkingTo in your DESCRIPTION:

    Imports: astronomyengine
    LinkingTo: astronomyengine
  2. Include the header in your C or C++ source files:

    #include <astronomy/astronomy.h>

For detailed documentation of the C API, including key types, functions, supported bodies, and coordinate frame rotations, see the Astronomy Engine C API documentation.

Copy Link

Version

Install

install.packages('astronomyengine')

Version

0.1.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Mitchell O'Hara-Wild

Last Published

February 27th, 2026

Functions in astronomyengine (0.1.0)

astro_geo_vector

Geocentric position vector of a celestial body
astro_helio_vector

Heliocentric position vector of a celestial body
astro_next_lunar_eclipse

Find the next lunar eclipse in a series
astro_make_time

Create an astronomical time value
astro_rotation_EQD_ECL

Rotation Matrix from Equatorial of-Date to J2000 Ecliptic
astro_moon_phase

Moon Phase Angle
astro_rotation_EQD_ECT

Rotation Matrix from EQD to ECT
astro_rotation_ECT_EQD

Rotation Matrix from ECT to EQD
astro_rotation_ECT_EQJ

Rotation Matrix from ECT to EQJ
astro_next_moon_quarter

Find Next Lunar Quarter
astro_rotate_vector

Apply a rotation to a vector
astro_pair_longitude

Ecliptic longitude of one body relative to another
astro_rotation_ECL_EQD

Rotation Matrix from J2000 Ecliptic to Equatorial of-Date
astro_rotation_EQJ_EQD

Rotation Matrix from EQJ to EQD
astro_pivot

Re-orient a rotation matrix by pivoting around an axis
astro_observer_state

Observer position and velocity vector from geographic coordinates
astro_observer_vector

Observer position vector from geographic coordinates
astro_rotation_EQJ_HOR

Rotation Matrix from J2000 Equatorial to Horizontal
astro_rotation_EQJ_GAL

Rotation Matrix from EQJ to GAL
astro_rotation_HOR_ECL

Rotation Matrix from HOR to ECL
astro_rotation_HOR_EQD

Rotation Matrix from HOR to EQD
astro_rotation_GAL_EQJ

Rotation Matrix from GAL to EQJ
astro_search_transit

Search for a transit of Mercury or Venus
astro_search_sun_longitude

Search for Sun longitude
astro_search_rise_set

Search for the next rise or set time of a celestial body
astro_search_relative_longitude

Search for relative longitude event between Earth and another planet
astro_search_altitude

Search for when a body reaches a specified altitude
astro_rotation_EQD_HOR

Rotation Matrix from EQD to HOR
astro_search_hour_angle

Search for when a body reaches a specified hour angle
astro_observer_gravity

Observer gravitational acceleration
astro_next_transit

Search for the next transit of Mercury or Venus
astro_rotation_EQD_EQJ

Rotation Matrix from EQD to EQJ
astro_rotation_HOR_EQJ

Rotation Matrix from Horizontal to J2000 Equatorial
next_local_solar_eclipse

Search for the next local solar eclipse
next_lunar_apsis

Find the next lunar apsis event
astro_search_lunar_eclipse

Search for a lunar eclipse
search_local_solar_eclipse

Search for a local solar eclipse
search_lunar_apsis

Search for lunar apsis events
astro_seasons

Equinoxes and Solstices for a Given Year
astro_sphere_from_vector

Convert Cartesian Vector to Spherical Coordinates
astro_vector_from_sphere

Convert Spherical Coordinates to Cartesian Vector
next_planet_apsis

Find the next planetary apsis in a series
astro_vector_observer

Geographic coordinates from observer position vector
search_global_solar_eclipse

Search for a global solar eclipse
astro_search_moon_quarter

Find First Lunar Quarter
astro_search_peak_magnitude

Search for peak magnitude of Venus
astro_rotation_EQJ_ECT

Rotation Matrix from EQJ to ECT
astro_rotation_EQJ_ECL

Rotation Matrix from EQJ to ECL
astro_rotation_ECL_HOR

Rotation Matrix from ECL to HOR
astro_rotation_ECL_EQJ

Rotation Matrix from ECL to EQJ
search_planet_apsis

Search for the next planetary apsis
astro_sun_position

Sun's position in ecliptic coordinates
astro_search_moon_phase

Search for a Specific Moon Phase
astro_search_max_elongation

Search for maximum elongation
astro_vector_from_horizon

Convert Horizontal Coordinates to Cartesian Vector
astronomyengine-package

astronomyengine: R Bindings to the 'Astronomy Engine' C Library
next_global_solar_eclipse

Search for the next global solar eclipse
astro_elongation

Elongation of a celestial body
astro_body_code

Get the integer code for a celestial body by name
astro_ecliptic

Convert J2000 equatorial coordinates to ecliptic coordinates
astro_current_time

Current UTC time according to Astronomy Engine
astro_ecliptic_longitude

Heliocentric ecliptic longitude of a body
astro_body

Celestial body codes
astro_combine_rotation

Combine two rotation matrices
astro_body_name

Get the name of a celestial body
astro_bary_state

Barycentric position and velocity vectors
astro_angle_from_sun

Angle from the Sun
astro_horizon

Horizontal coordinates of a celestial body
astro_identity_matrix

Create an identity rotation matrix
astro_hour_angle

Calculate the hour angle of a body
astro_horizon_from_vector

Convert Cartesian Vector to Horizontal Coordinates
astro_equator

Topocentric equatorial coordinates of a celestial body
astro_inverse_rotation

Calculate the inverse of a rotation matrix
astro_illumination

Illumination data for a celestial body
astro_equator_from_vector

Convert Cartesian Vector to Equatorial Coordinates