Warning messages: All formats failed to parse. No formats found - lubridate date interval

In order to calculate the status of late products, I wanted to subtract order date and shipping date of the product.

Sales1 <- data1 %>%
  mutate(orderdate = dmy('Order Date'), shipdate = dmy('Ship Date'),
         number_days = interval(orderdate,shipdate)/ddays(),
         LateValue = if_else(number_days>2,"Late","NotLate"),
         idLateStatus = row_number())

However, I am getting warning message as all formats failed to parse and there are no values shown in the table as well. It would be helpful for me if someone can suggest any ideas.

Thank You

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

This is just a guess (since I can’t run this code), but I think you are using single quotes where you need to use backticks.

torderdate = dmy('Order Date')

results in the string "Order Date" being passed to dmy(), which obviously is not a parse-able date. Give this a try:

Sales1 <- data1 %>%
  mutate(orderdate = dmy(`Order Date`), shipdate = dmy(`Ship Date`),
         number_days = interval(orderdate,shipdate)/ddays(),
         LateValue = if_else(number_days>2,"Late","NotLate"),
         idLateStatus = row_number())
1 Like

@mara , I have installed the package and here with the other information

Input details:

install.packages("reprex")
library(DBI)
library(RPostgreSQL)
library(readr)
library(dplyr)
library(tidyr)
library(lubridate)

Sales1 <- data1 %>%
  mutate(orderdate = dmy('Order Date'), shipdate = dmy('Ship Date'),
         number_days = interval(orderdate,shipdate)/ddays(),
         LateValue = if_else(number_days>2,"Late","NotLate"),
         idLateStatus = row_number())

Output is:

> Sales1 <- data1 %>%
+   mutate(orderdate = dmy('Order Date'), shipdate = dmy('Ship Date'),
+          number_days = interval(orderdate,shipdate)/ddays(),
+          LateValue = if_else(number_days>2,"Late","NotLate"),
+          idLateStatus = row_number())
Warning messages:
1: All formats failed to parse. No formats found. 
2: All formats failed to parse. No formats found.

@jcblum , I tried using the double quoted but still the same warning message

Did you try copying and pasting exactly what I posted? It’s using backticks, which is a different character from both single and double quote marks. Unfortunately, some non-English keyboard layouts make it very difficult to type a backtick. On a typical US QWERTY keyboard layout it’s to the left of the 1 key. Here is where it’s found on a few other layouts.

R uses both single and double quote marks to identify character strings. R allows you to use backticks to enclose otherwise invalid names (such as Order Date, which can’t be used on its own because it has a space in it).

@jcblum, Yeah it works now. Thank you so much :slight_smile:

1 Like