Learn R Programming

suntools

suntools provides functions for calculating the sun's position, sunrise, sunset, solar noon, and crepuscular (twilight) times for any given geographical location and time on earth. Functions in suntools used to be part of the maptools package. The functions are based on equations provided by the National Oceanic & Atmospheric Administration (NOAA).

Main package functions:

  • crepuscule(): Calculates crepuscular (twilight) times, i.e. the time of dawn or dusk.
  • sunriset(): Calculates the times of sunrise and sunset at a given location.
  • solarpos(): Calculates the solar position (elevation and azimuth) at a given location and time.
  • solarnoon(): Calculates solar noon time at a given location.

Installation

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

install.packages("suntools")

Alternatively, you can install the development version from GitHub with:

devtools::install_github("adokter/suntools")

Example

library(suntools)

#Calculate sunset in Ithaca, NY, USA on June 1, 2023

sunriset(
  matrix(c(-76.4511, 42.4800), nrow = 1),
  as.POSIXct("2023-06-01", tz = "America/New_York"),
  direction='sunset',
  POSIXct.out=TRUE
)

#  day_frac                time
#1 0.858628 2023-06-01 20:36:25

Author(s)

References

This package uses algorithms provided by the National Oceanic & Atmospheric Administration (NOAA), for more information see

Copy Link

Version

Install

install.packages('suntools')

Monthly Downloads

1,472

Version

1.1.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Adriaan M. Dokter

Last Published

November 7th, 2025

Functions in suntools (1.1.0)

solarpos

Compute solar position
.balanceCrdsTimes

Balance coordinates and times
sunriset

Calculate sunrise/sunset
solarnoon

Compute solar noon time
crepuscule

Compute crepuscular time
dls_correction

Correct for daylight savings day length change
suntools-package

suntools: calculate sun position, sunrise, sunset, solar noon and twilight