#r #json #jsonlite
#r #json #jsonlite
Вопрос:
У меня есть два отдельных объекта в R, которые имеют формат JSON, и я пытаюсь преобразовать в один объект R с двумя объектами JSON в его структуре
это мой код..
studies <- get_studies(efo_trait = 'triple-negative breast cancer')
study <- studies@studies
publication <- studies@publications
paste("studies", study, "publication", publication)
это то, что я получаю в json
[
"studies c("GCST002305", "GCST010100") publication c("GCST002305", "GCST010100")",
"studies c("Breast cancer (estrogen-receptor negative, progesterone-receptor negative, and human epidermal growth factor-receptor negative)", "Breast cancer (estrogen-receptor negative, progesterone-receptor negative, and human epidermal growth factor-receptor negative)") publication c(24325915, 32424353)",
"studies c("1,529 European ancestry cases, 3,399 European ancestry controls", "8,602 European ancestry triple negative cases, 9,414 European ancestry BRCA1 mutation carrier cases, 100,971 European ancestry controls") publication c(16048, 18399)",
"studies c("2,148 European ancestry cases, 1,309 European ancestry controls", NA) publication c("Carcinogenesis", "Nat Genet")",
"studies c(FALSE, FALSE) publication c("Genome-wide association study identifies 25 known breast cancer susceptibility loci as risk factors for triple-negative breast cancer.", "Genome-wide association study identifies 32 novel breast cancer susceptibility loci from overall and subtype-specific analyses.")",
"studies c(FALSE, FALSE) publication c("Purrington KS", "Zhang H")",
"studies c(NA, 9700000) publication c("0000-0002-5710-1692", NA)",
"studies c(NA, "~") publication c("GCST002305", "GCST010100")",
"studies c(TRUE, TRUE) publication c(24325915, 32424353)",
"studies c(FALSE, FALSE) publication c(16048, 18399)",
"studies c(NA, NA) publication c("Carcinogenesis", "Nat Genet")",
"studies c(FALSE, FALSE) publication c("Genome-wide association study identifies 25 known breast cancer susceptibility loci as risk factors for triple-negative breast cancer.", "Genome-wide association study identifies 32 novel breast cancer susceptibility loci from overall and subtype-specific analyses.")",
"studies c(FALSE, TRUE) publication c("Purrington KS", "Zhang H")"]
но мне нужен этот тип данных…
[
studies: {
"study_id": "GCST002305",
"pubmed_id": 24325915,
"publication_date": "2013-12-09",
"publication": "Carcinogenesis",
"title": "Genome-wide association study identifies 25 known breast cancer susceptibility loci as risk factors for triple-negative breast cancer.",
"author_fullname": "Purrington KS",
"author_orcid": "0000-0002-5710-1692"
}
publication: {
"study_id": "GCST010100",
"pubmed_id": 32424353,
"publication_date": "2020-05-17",
"publication": "Nat Genet",
"title": "Genome-wide association study identifies 32 novel breast cancer susceptibility loci from overall and subtype-specific analyses.",
"author_fullname": "Zhang H"
}
]
Пожалуйста, помогите мне
Комментарии:
1. paste() — это векторизованная функция, поэтому она пытается прочитать первый элемент из каждого и вставить их вместе, второй из каждого и т.д. Вы хотите обрабатывать свои исходные объекты так, как будто каждый из них представляет собой одну строку, поэтому вам нужно преобразовать их в это… или, возможно, используйте
cat()
функцию.2. как мне использовать cat()
3. не могли бы вы поделиться выводом
dput(studies)
?4. Читать ?cat. Есть и другие варианты.