Function that uses a parameter to form an as.POSIXct function

"Sorkin, John" <[email protected]> Thu, 26 Feb 2026 15:23:04 +0000
Newsgroups gmane.comp.lang.r.general
Message-ID <DM6PR03MB5049ED65D2B85DB14F3FC4B6E272A@DM6PR03MB5049.namprd03.prod.outlook.com>
I am trying to write a function which will take accept an argument and use the value of the argument to indicate the source of the data that should be processed in an as.POSIXct function. My attempt at writing the function is below:

readit <- function(species){
  no[,"NewTime"] <- as.POSIXct(paste(species)[,"Time"],format=("%Y-%m-%d_%H:%M:%OS"),tz="UTC")
}

If the value of species is no2, I want the function call
readit("no2")
to produce a statement:
no[,"NewTime"] <- as.POSIXct(no[,"Time"],format=("%Y-%m-%d_%H:%M:%OS"),tz="UTC")

If the value of species is co2, I want the function call
readit("co2")
to produce a statement:
no[,"NewTime"] <- as.POSIXct(co2[,"Time"],format=("%Y-%m-%d_%H:%M:%OS"),tz="UTC")

When I run either version of the function and the call to the function I receive the following error message:

Browse[1]> readit("no2")
Error during wrapup: incorrect number of dimensions
Error: no more error handlers available (recursive errors?); invoking 'abort' restart

Please help me fix my code

Thank you,

John

John David Sorkin M.D., Ph.D.
Professor of Medicine, University of Maryland School of Medicine;
Associate Director for Biostatistics and Informatics, Baltimore VA Medical Center Geriatrics Research, Education, and Clinical Center; 
Former PI Biostatistics and Informatics Core, University of Maryland School of Medicine Claude D. Pepper Older Americans Independence Center;
Senior Statistician University of Maryland Center for Vascular Research;

Division of Gerontology, Geriatrics and Palliative Medicine,
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
Cell phone 443-418-5382