RStudio: Go from disabled citation insert to enabled citation insert.

I would like to go from having the citations insert tool disabled in RStudio to having it enabled. Is there a list of steps for that?

At this point in the visual editor (CTRL + SHIFT + 8) is disabled, indicating there are steps that need to be done. I am looking for a list of these steps.

---
title: "test citations"
output: html_document
bibliography: bibliography.json
link-citations: true
---
knitr::opts_chunk$set(echo = TRUE)

The bibliography.json file

[
	{
		"id": "http://zotero.org/users/3431025/items/TF8WG2T8",
		"type": "webpage",
		"title": "Gestational diabetes insipidus: a review of an underdiagnosed condition - PubMed",
		"URL": "https://pubmed.ncbi.nlm.nih.gov/20500966/",
		"accessed": {
			"date-parts": [
				[
					"2021",
					6,
					15
				]
			]
		}
	},
	{
		"id": "http://zotero.org/users/3431025/items/U9VF3T98",
		"type": "webpage",
		"title": "Gestational diabetes insipidus: a review of an underdiagnosed condition - PubMed",
		"URL": "https://pubmed.ncbi.nlm.nih.gov/20500966/",
		"accessed": {
			"date-parts": [
				[
					"2021",
					6,
					15
				]
			]
		}
	}
]

Thanks.

Can you tell us what you are doing? As far as I can see there is no citation insert in basic RStudio. Are you working in a Rmd document?
Do you have something like

bibliography: Roman.bib
csl: apa.csl

in the YAML?

If so, try knitting the document. For some reason the Rmd file sometimes seems to fail the recognize the bibliography until after an initial knit after the document is loaded.

Otherwise can you supply us with a reproducible example (reprex)

When I mentioned citations insert tool disabled, that might have been misleading, I'm not trying to write code or fix an "error." I just want a "hello world" version of using a CLS json formatted zotero export to a markdown document that uses a reference. But I will add what my document currently looks like to reflect the progress made since posting.

If you could explain why you are using a .bib in your example when according to what I have read, .json is recommended. Also, I never understood the requirement for csl: apa.csl. If you could explain that and how it fits in, that would partly answer my question.

I am not using a .bib in the example---well my last one anyway. Our responses may have passeh each other.
It is just that somewhere i noticed that a rmd file was supposed to have "bib" in its name. I have no idea why.

My [last] example uses a .json file ( see the .json) extension.

I normally use the American Psychology Association style manual and

csl: apa.csl

specifies that this is the form in which I want my bibliography formatted .

Ouch, I forgot that to get my examples to run you need the apa.csl file in your directory. It , and thousands of others, are downloadable from Zotero Style Repository

Did you post an example?

Yes but it seems to be held up in moderation.

guess what my gmail is.

Okay, I see the problem but I have no idea how to solve it. I use bibtex files. However I tried with a .json file exported from my copy of Zotero and it seems fine.

---
title: '"test citations"'
author: "toucan"
date: "21/06/2021"
output: pdf_document
bibliography: export.bib.json
csl: apa.csl
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

It was a dark and stormy night [@campbellGoddaughterGinaGallo2012]



and my file
{
	"id": "campbellGoddaughterGinaGallo2012",
	"type": "book",
	"abstract": "Gina Gallo is a gemologist who would like nothing better than to run her little jewelry shop. Unfortunately she's also \"the Goddaughter,\" and, as she tells her new friend Pete, \"you don't get to choose your relatives.\" And you can't avoid them when you live in Hamilton and they more or less run the place. When Gina bumps into Pete at the Art Gallery Gala, sparks fly. So do bullets, when her cousin Tony is taken down by rival mobsters from New York. It turns out Tony was carrying a load of hot gems in the heel of his shoe. When Gina is reluctantly recruited to carry the rocks back to Buffalo, the worst happens: they get stolen. Pete and Gina have no choice but to steal them back, even though philandering politicians, shoe fetishists, and a trio of inept goons stand in their way. It's all in a day's work, when you're the Goddaughter.",
	"event-place": "Victoria, B.C",
	"ISBN": "978-1-4598-0125-7",
	"language": "English",
	"number-of-pages": "144",
	"publisher": "Orca Book Publishers",
	"publisher-place": "Victoria, B.C",
	"source": "Amazon",
	"title": "The Goddaughter: A Gina Gallo Mystery",
	"title-short": "The Goddaughter",
	"author": [
		{
			"family": "Campbell",
			"given": "Melodie"
		}
	],
	"issued": {
		"date-parts": [
			[
				"2012",
				9,
				1
			]
		]
	}
},
{
	"id": "jonasson100YearOldManWho2012",
	"type": "book",
	"abstract": "After a long and eventful life, Allan Karlsson ends up in a nursing home, believing it to be his last stop. The only problem is that he’s still in good health, and one day, he turns 100. A big celebration is in the works, but Allan really isn’t interested (and he’d like a bit more control over his alcohol consumption). So he decides to escape. He climbs out the window in his slippers and embarks on a hilarious and entirely unexpected journey. It would be the adventure of a lifetime for anyone else, but Allan has a larger-than-life backstory: Not only has he witnessed some of the most important events of the twentieth century, he has actually played a key role in them. Quirky and utterly unique, The 100-Year-Old Man Who Climbed Out the Window and Disappeared has charmed readers across the world.",
	"language": "English",
	"number-of-pages": "528",
	"publisher": "HarperCollins Publishers",
	"source": "Amazon",
	"title": "The 100-Year-Old Man Who Climbed Out The Window And Disappeared",
	"author": [
		{
			"family": "Jonasson",
			"given": "Jonas"
		}
	],
	"issued": {
		"date-parts": [
			[
				"2012",
				8,
				28
			]
		]
	}
},
{
	"id": "macaulayMotelMysteries1979",
	"type": "book",
	"abstract": "It is the year 4022; all of the ancient country of Usa has been buried under many feet of detritus from a catastrophe that occurred back in 1985. Imagine, then, the excitement that Howard Carson, an amateur archeologist at best, experienced when in crossing the perimeter of an abandoned excavation site he felt the ground give way beneath him and found himself at the bottom of a shaft, which, judging from the DO NOT DISTURB sign hanging from an archaic doorknob, was clearly the entrance to a still-sealed burial chamber. Carson's incredible discoveries, including the remains of two bodies, one of then on a ceremonial bed facing an altar that appeared to be a means of communicating with the Gods and the other lying in a porcelain sarcophagus in the Inner Chamber, permitted him to piece together the whole fabric of that extraordinary civilization.",
	"edition": "Later Printing edition",
	"event-place": "Boston",
	"ISBN": "978-0-395-28425-4",
	"language": "English",
	"number-of-pages": "96",
	"publisher": "HMH Books for Young Readers",
	"publisher-place": "Boston",
	"source": "Amazon",
	"title": "Motel of the Mysteries",
	"author": [
		{
			"family": "Macaulay",
			"given": "David"
		}
	],
	"issued": {
		"date-parts": [
			[
				"1979",
				10,
				11
			]
		]
	}
},
{
	"id": "klamWhoRichNovel2017",
	"type": "book",
	"abstract": "A provocative satire of love, sex, money, and politics that unfolds over four wild days in so-called “paradise”—the long-awaited first novel from the acclaimed author of Sam the Cat “I seriously, deeply love this book.”—Michael CunninghamNAMED ONE OF THE BEST BOOKS OF THE YEAR BY THE NEW YORK TIMES AND THE WASHINGTON POST Every summer, a once-sort-of-famous cartoonist named Rich Fischer leaves his wife and two kids behind to teach a class at a weeklong arts conference in a charming New England beachside town. It’s a place where, every year, students—nature poets and driftwood sculptors, widowed seniors, teenagers away from home for the first time—show up to study with an esteemed faculty made up of prizewinning playwrights, actors, and historians; drunkards and perverts; members of the cultural elite; unknown nobodies, midlist somebodies, and legitimate stars—a place where drum circles happen on the beach at midnight, clothing optional.   Once more, Rich finds himself, in this seaside paradise, worrying about his family’s nights without him and trying not to think about his book, now out of print, or his future as an illustrator at a glossy magazine about to go under, or his back taxes, or the shameless shenanigans of his colleagues at this summer make-out festival. He can’t decide whether his own very real desire for love and human contact is going to rescue or destroy him.   A warped and exhilarating tale of love and lust, Who Is Rich? goes far beyond to address deeper questions: of family, monogamy, the intoxicating beauty of children, and the challenging interdependence of two soulful, sensitive creatures in a confusing domestic alliance.LONGLISTED FOR THE CENTER FOR FICTION FIRST NOVEL PRIZE“Funny, maddening . . . defiantly original . . . [Matthew] Klam’s prose is so clean, so self-assured, that it feels a little like a miracle.”—The New York Times “A dazzling meditation on monogamy [and] parenthood . . . full of sound and fury and signifying pretty much everything.”—The Boston Globe “Comic, wondrous, and sad.”—The New Yorker “Almost scarily astute.”—People “An electric amalgam of frustration and tenderness, wonder and rebellion: a paean to the obliterating power of parental love.”—Jennifer Egan “A contemporary masterpiece.”—Salon",
	"edition": "1st edition edition",
	"event-place": "New York",
	"ISBN": "978-0-8129-9798-9",
	"language": "English",
	"number-of-pages": "336",
	"publisher": "Random House",
	"publisher-place": "New York",
	"source": "Amazon",
	"title": "Who Is Rich?: A Novel",
	"title-short": "Who Is Rich?",
	"author": [
		{
			"family": "Klam",
			"given": "Matthew"
		}
	],
	"issued": {
		"date-parts": [
			[
				"2017",
				7,
				4
			]
		]
	}
},
{
	"id": "lewisEvolutionManHow1994",
	"type": "book",
	"abstract": "Here is a typical Stone Age family, reimagined by Roy Lewis in this hilarious novel as characters in some glittering drawing-room comedy. Father, who has a scientific turn of mind, has just discovered fire. Mother makes sure the children finish supper, even when the plat du jour is toad. Uncle Vanya thinks that the species has been flirting with disaster ever since it began to chip flint into tools. While little Alexander has gotten himself in deep trouble by making the first cave painting: artists are always so misunderstood.Long out of print, The Evolution Man would make Charles Darwin turn over in his grave. Lewis has written a witty, intelligent satire of the lives of our remote ancestors, complete with highly revisionist accounts of everything from the origins of courtship to the staples of Pleistocene cuisine. It's the funniest thing to happen to prehistory since Raquel Welch donned a fur bikini in One Million B.C.",
	"edition": "1st Vintage Contemporaries Ed edition",
	"event-place": "New York",
	"ISBN": "978-0-679-75009-3",
	"language": "English",
	"note": "tex.ids: lewis_evolution_1994-1",
	"number-of-pages": "213",
	"publisher": "Vintage",
	"publisher-place": "New York",
	"source": "Amazon",
	"title": "Evolution Man: Or, How I Ate My Father",
	"title-short": "Evolution Man",
	"author": [
		{
			"family": "Lewis",
			"given": "Roy"
		}
	],
	"issued": {
		"date-parts": [
			[
				"1994",
				8,
				30
			]
		]
	}
},
{
	"id": "mchughenDNADemystifiedUnravelling2020",
	"type": "book",
	"abstract": "\"For all those who fear they cannot understand the science of DNA -- they will soon find that they can and it's fascinating.\" -- Matt Ridley, author of Genome: The Autobiography of a Species in 23 Chapters DNA, once the exclusive domain of scientists in research labs, is now the darling of popular and social media. With personal genetic testing kits in homes and GMO foods in stores, DNA is an increasingly familiar term. Unfortunately, what people know, or think they know, about DNA and genetics is often confused or incorrect. Contrary to popular belief, for instance, genes don't \"skip a generation\" and, no, human DNA is not \"different\" from DNA of other species. With popular misconceptions proliferating in the news and on the internet, how can anyone sort fact from fiction? DNA Demystified satisfies the public appetite for and curiosity about DNA and genetics. Alan McHughen, an accomplished academic and public science advocate, brings the reader up-to-speed on what we know, what we don't, and where genetic technologies are taking us. The book begins with the basic groundwork and a brief history of DNA and genetics. Chapters then cover newsworthy topics, including DNA fingerprinting, using DNA in forensic analyses, and identifying cold-case criminals. For readers intrigued by the proliferation of at-home DNA tests, the text includes fascinating explorations of genetic genealogy and family tree construction-crucial for people seeking their biological ancestry. Other chapters describe genetic engineering in medicine and pharmaceuticals, and the use of those same technologies in creating the far more controversial GMOs in food and agriculture. Throughout, the book raises provocative ethical and privacy issues arising from DNA and genetic technologies.With the author's comprehensive expertise, DNA Demystified offers an informal yet authoritative guide to the genetic marvel of DNA.",
	"event-place": "New York",
	"ISBN": "978-0-19-009296-2",
	"language": "English",
	"number-of-pages": "392",
	"publisher": "Oxford University Press",
	"publisher-place": "New York",
	"source": "Amazon",
	"title": "DNA Demystified: Unravelling the Double Helix",
	"title-short": "DNA Demystified",
	"author": [
		{
			"family": "McHughen",
			"given": "Alan"
		}
	],
	"issued": {
		"date-parts": [
			[
				"2020",
				6,
				2
			]
		]
	}
}

]

This note is actually the answer to my question:

If you use the RStudio Visual editor (Select the pen tip shortcut icon on the upper right of the "source" Pane) , your cursor has to be in the text area: outside the YAML and outside any code block, for the @ on the shortcut icon bar (just under the "tabs" bar at the top of the "source" Pane) to activate. If you get that, then non of the other steps relating to formatting the YAML are needed. (You won't need to enter any YAML entries, RStudio will make some entries.) RStudio provides a menu to locate your references when you select the @ shortcut. This includes Zotero if installed. It also includes your YAML identified bibliography

bibliography: references.json

Other engines included are

a. From DOI
b. crossref
c. DataCite
d. PubMed

References can be taken from any of these. When you knit, or at some point, references that you add from sources such as PubMed are then inserted into your bibliography file as pointed to in your YAML.

Although, in the end not needed as explained above:

I copied your code and also downloaded the apa.csl file (GitHub - citation-style-language/styles: Official repository for Citation Style Language (CSL) citation styles.) and now I am able to knit. Also, I can insert citations using the RStudio visual editor.

My YAML is

title: '"test citations"'
author: "Harlan"
date: "21/06/2021"
output: pdf_document
bibliography: references.json
link-citations: true
csl: apa.csl

A couple things to note:

  1. In the JSON there is a key called "id": containing the text that gets inserted after the "@"
    JSON
    "id": "campbellGoddaughterGinaGallo2012",

RMarkdown
[@campbellGoddaughterGinaGallo2012]

  1. The entire JSON file starts with a [ and end with a ] The entries inside are separated by a comma. see CSL-JSON — citeproc-js 1.1.73 documentation

  2. The YAML directive csl: apa.csl controls how the citation is formatted, In this case APA style is used. It is also possible, if you want, to make up your own style. The file referenced contains the template. See Zotero Style Repository for style files you can download

Excellent, a very nice explanation.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.