-1

I am a noob trying to troubleshooting an R script written by someone else. The script used to work, but now does not. It is related to apply(), which is apply(X, MARGIN, FUN, ...). That says to me that format_date is supposed to be a function. But the person who wrote this script did not define a function called format_date, and I can't find this function in the libraries that are called in the script. Where do I find format_date?

The reason for this line is that the index of this table is date. But we need a date field to export (and not just date as the index), so we are appending it on.

Here is the line throwing the error:

result$date = apply(rownames(result), 1, format_date) # add in date to dataframe

Here is the error message:

Warning: Ignoring unknown parameters: fill Saving 7 x 7 in image Error in apply(rownames(result), 1, format_date) : object 'format_date' not found

  • 1
    You can try searching [RDocumentation](https://www.rdocumentation.org/) for functions in packages. [There's a function](https://www.rdocumentation.org/packages/rtweet/versions/0.3.7/topics/format_date) named `format_date` in an old version of the rtweet package. If it's a custom function that you no longer have, we can't help you. – neilfws Aug 29 '18 at 22:45
  • 1
    Two other methods of research that work for me: google [`cran format_date`](https://www.google.com/search?q=cran+format_date), often pointing to a full package on the CRAN repo; and using rseek.org, search for the function name [`format_date`](https://rseek.org/?q=format_date). Both often give some good pointers. – r2evans Aug 29 '18 at 22:50
  • Thanks. I just called the library --> require('retweet'). However, the error says there is no package called retweet. Does that mean the package was recently disabled.Here's the error now --> Loading required package: retweet Warning: Ignoring unknown parameters: fill Saving 7 x 7 in image Error in apply(rownames(result), 1, format_date) : object 'format_date' not found In addition: Warning messages: 1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘retweet’ – user3329491 Aug 29 '18 at 22:51
  • 1
    Another problem: last I checked, `rownames(result)` (assuming a frame or matrix) will return a vector, for which `apply(..., 1, ...)` does not make sense. If you make this question more reproducible (including sample data), we might be able to assist better. Refs for reproducibility: https://stackoverflow.com/questions/5963269/, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Aug 29 '18 at 22:51
  • Ok, i tried rtweet and exuber. Are you all saying that packages and libraries will often become inactive and therefore I cannot use the function within the library anymore? It was only 2 weeks ago that the script was working. Also, I'm working on that reproducible example. – user3329491 Aug 29 '18 at 23:08
  • "Become inactive" makes sense if you mean "restart R and don't call `library(...)`". When you run `library(exuber)` and `library(rtweet)`, do either one succeed? Does your script now work? – r2evans Aug 29 '18 at 23:23
  • "no package named ..." means that you have to install it. But note that the function doesn't exist in the latest version of rtweet. – neilfws Aug 29 '18 at 23:35
  • Thanks! Now it it working, but the file is still writing blank. There is another error I have to figure out. I will try to post something with full code. – user3329491 Aug 29 '18 at 23:44
  • Dear user 332, it looks like you solved this given problem. So you can write an answer and accept it. – Artem Sep 15 '18 at 10:04

1 Answers1

0

You can comment out or delete line result$date = apply(rownames(result), 1, format_date) from your code.

In older version of rtweet package the function format_date converted datetime Twitter API format to standard datatime objects. Current version of rtweet functions return datetime (like POSIX) objects so there is no need for function like format_date.

Artem
  • 3,304
  • 3
  • 18
  • 41