-
-
Save MattSandy/14242b5af9dce69102647e2000848bcc to your computer and use it in GitHub Desktop.
library(tidyverse) | |
library(jsonlite) | |
df <- "https://api.inc.com/rest/i5list/2022" %>% | |
fromJSON() %>% | |
.$companies %>% | |
bind_rows() %>% | |
group_by(inc5000companyId) %>% | |
mutate( | |
article = ifelse(is.null(article %>% unlist %>% .[1]),NA,article %>% unlist %>% .[1]), | |
editorsPick = editorsPick %>% unlist %>% paste(collapse = ",") | |
) %>% | |
write_csv("inc.csv") |
This relies on the tidyverse and jsonlite package, so those must be installed first.
I managed to get it working. Used a different CRAN mirror and changed the path.lib to get the packages installed properly. I ran the code and Matt you are a bloody legend. I literally can't thank you enough cause I saved about 3 weeks of my time. God bless you man you are incredible!
Hi Matt,
I figured to extract the company profile from "https://api.inc.com/rest/companyprofile/blockfi" but I'm able to extract the profile of only one company at a time and finding difficulty saving it in .cvs
Any possibility to list out all the 5000 profiles? please help.
library(tidyverse)
library(jsonlite)
df <- "https://api.inc.com/rest/companyprofile/blockfi" %>%
- fromJSON() %>%
- .$profile %>%
- bind_rows() %>%
- group_by(inc5000companyId) %>%
- mutate(
-
article = ifelse(is.null(article %>% unlist %>% .[1]),NA,article %>% unlist %>% .[1]),
-
editorsPick = editorsPick %>% unlist %>% paste(collapse = ",")
- ) %>%
- write_csv("profiles.csv")
Error inmutate()
:
! Problem while computingarticle = ifelse(...)
.
ℹ The error occurred in group 1: inc5000companyId = "130719".
Caused by error inunlist()
:
! object 'article' not found
Runrlang::last_error()
to see where the error occurred.
I came this far with 0 subject in R
Hey Syamjordan
Did you ever figure it out?
Hi Matt, if I want to rerun the list for 2023 is it as simple as changing the URL in the code above to "https://www.inc.com/inc5000/2023"?
Hi Matt,
Thank you for writing out this code. I have minimal Python experience and I am very new to R. I keep getting an error that says:
Error in "https://api.inc.com/rest/i5list/2022" %>% from JSON() %>% .$companies %>% :
could not find function "%>%"
I tried to install the ("magrittr") package as that was a general recommendation but that did not help.
Thank you in advance for any assistance!
TF