You seem to be confusing two ways of producing a pdf.
Sweave is a part of base R, and lets you include R code in an .Rnw file that will be 'sweaved' into a tex file with the results of the R code. You can then use a tex implementation to render that tex file into a PDF file.
You can also use R to produce plots and other graphic objects straight into a pdf file using the pdf() function.
To include your plot into a sweave document, replace your plot chunk with
<<name="Figure", echo=F, figure=True>>=
plot(1:10,1:10)
@
Then save your file and sweave it. sweave should produce a pdf and eps version fo your graph along with a tex document. Then run texi2dvi to produce a pdf.
For a fresh user to Anki using LaTeX and Miktex there is a sharp initial learning curve with several pitfalls.
When you enter LaTeX code into Anki it is best to start with the simplest of examples so to get a Question and Answer such as
You need to start with this simple entry
Does the divergent p-series
[latex]\begin{math}\sum_{k = 1}^{\infty}\frac{1}{k}\end{math}[/latex]
converge?
The series converges for p>1 and diverges for 0<p≤1. With p=1 it is called the Harmonic Series.
The first error message may be
Error executing latex.
Generated file: C:\Users\yourname\AppData\Local\Temp\anki_temp\tmp.tex
Have you installed latex and dvipng/dvisvgm?
This could mean you have not installed MiKTeX correctly (including setting the paths). To check this open command line and try and run latex, dvipng, and dvisvgm and make sure the system can find these. If the system can find all these programs, the error message can also be generated by Anki not having sufficient privileges to fetch all necessary packages. Try running Anki one time in Administrator mode.
IF you get other error messages then either your latex code is not right or MiKTeX has not been configured correctly.
One test to see what is happening is to check Anki's TeX output which is a file
%temp%\anki_temp\tmp.tex
(you can enter %temp%\anki_temp in windows explorer address bar to get there quickly) If you open tmp.tex in notepad then check/verify its contents are identical to the MWE shown below .
It is best to run MiKTeX-console and ensure it is fully stable before Anki calls it in the background.
The best way to check MiKTeX can run the same code as above is to use the included TeXworks editor and run the same minimal example until it works.
\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath}
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}
\begin{math}\sum_{k = 1}^{\infty}\frac{1}{k}\end{math}
\end{document}
so it should show
Once you are confident that the above simple sample works with TeXworks IT should then work in Anki and in the temp directory (see above) you will find half a dozen files including two trace logs the short one is latex_log.txt (which Anki feeds back to the user) also is the more useful tmp.log with more useful information from the tex compilation.
In summary
Although the Anki manual and other older guides suggest settings are changed to "Install missing packages on the fly" is set to "No", not to "Ask me first" It is essential that MiKTeX is allowed to update itself
Thus I recommend the following (until someone corrects me as to why not?)
DO use the setting "Always install missing packages on the fly" until you have a stable setup, then (if you must) switch it to no.
While you are there in the console ensure amsfonts and miktex-dvipng-bin-2.9 have been added to the active packages (there should be a date under "installed on", it has also been recommended to include passivetex and ucs packages to clear the above utf8x error, however the simple example above runs correctly without it. It is easy to add or remove it using + and -.
Most importantly, periodically enter MiKTeX-console to manually force Tasks Refresh file name database
as well as Refresh font map files
this ensures your errors messages are minimal.
Whatever the problem is with Anki this TeX forum will require to see the contents of tmp.tex (what we may call the MWE) within your question so as to see what caused any error messages reported in the logs. It may also be useful to add the [latex] blah bla blah [/latex] line you used within Anki (although that should by default be included in the tmp.tex that you post).
If you customise LaTeX calling from Anki using the "Edit LaTeX build process" with the add-on from https://ankiweb.net/shared/info/937148547 or one of its variants then we will also need to know it was added and certainly what was changed especially if you extend to tikz or or other packages.
Best Answer
The solution that has worked for me has been to completely uninstall MikTex and install an older version (MiKTeX64-2.9.7269-basic) and not update Miktex or the packages. At first run, it gave me an error because could not find some packages and I installed them manually (for example 'grfext', which I downloaded from CTAN org, run the .dtx from my latex editor and it installed).
---> Win 10 64bits RStudio 1.4953